-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva11239.cpp
More file actions
83 lines (72 loc) · 1.9 KB
/
uva11239.cpp
File metadata and controls
83 lines (72 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
map <string, int> joiner;
map<string, int> allproject;
vector< pair<string, vector<string> > > allsoftware;
vector< pair<string, int> > eve;
vector<string> curjoiner;
string curstring;
string curproject;
int counter;
bool pairCmp(const pair<string, int > &a, const pair<string, int > &b) {
return a.second > b.second || (a.second == b.second && a.first.compare(b.first) < 0 );
}
void end_one_project() {
if(!curproject.empty()) {
allsoftware.push_back(make_pair(curproject, curjoiner));
}
curjoiner.clear();
}
void sumup_and_ready() {
end_one_project();
curproject = curstring;
allproject[curproject] = 0;
}
void add_student_to_project() {
if(joiner.find(curstring) == joiner.end()) {
joiner[curstring] = 1;
curjoiner.push_back(curstring);
} else {
if(find(curjoiner.begin(), curjoiner.end(), curstring) == curjoiner.end()) {
curjoiner.push_back(curstring);
joiner[curstring]++;
}
}
}
void cleanup() {
end_one_project();
for(int i = 0; i < allsoftware.size(); ++i) {
int counter = 0;
for(int j = 0; j < allsoftware[i].second.size(); ++j) {
if(joiner[allsoftware[i].second[j]] == 1)
counter++;
}
eve.push_back( make_pair(allsoftware[i].first, counter) );
}
sort(eve.begin(), eve.end(), pairCmp);
for(int i = 0; i < eve.size(); ++i) {
cout << eve[i].first << " " << eve[i].second << endl;
}
eve.clear();
joiner.clear();
allsoftware.clear();
curproject.clear();
}
int main() {
while( getline(cin, curstring) && curstring[0] != '0') {
if(curstring[0] >= 'A' && curstring[0] <= 'Z') {
sumup_and_ready();
} else if(curstring[0] >= 'a' && curstring[0] <= 'z') {
add_student_to_project();
} else if(curstring[0] == '1') {
cleanup();
}
}
return 0;
}