-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP11239.cpp
60 lines (54 loc) · 1.47 KB
/
P11239.cpp
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
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
string line;
while(true) { // cases
map<string,int> assignments;
set<string> banned;
map<string,int> projects;
map<int,string> rprojects;
int projectI = -1;
while(true) { // Read lines
getline(cin, line);
if(line[0] == '0')
return 0;
else if(line[0] == '1')
break;
else if(isupper(line[0])) { // new project:
++projectI;
projects[line] = projectI;
rprojects[projectI] = line;
}
else { // userid:
if(banned.find(line) != banned.end())
continue; // banned!
if(assignments.find(line) == assignments.end()) {// assign!
assignments[line] = projectI;
}
else {
if(assignments[line] != projectI) { // ban!
assignments.erase(line);
banned.insert(line);
}
}
}
} // read lines
// Compute output:
pair<int,string> *ret = new pair<int,string>[projects.size()];
for(map<string,int>::const_iterator it = projects.begin(); it != projects.end(); ++it) {
ret[it->second] = pair<int,string>(0, it->first);
}
for(map<string,int>::const_iterator it = assignments.begin(); it != assignments.end(); ++it) {
--ret[it->second].first;
}
sort(ret, ret+projects.size());
for(unsigned int i = 0; i < projects.size(); ++i) {
cout << ret[i].second << " " << (-ret[i].first) << endl;
}
delete[] ret;
} // while(true) for cases
} // int main