-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopensource.cpp
45 lines (45 loc) · 945 Bytes
/
opensource.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
#include<bits/stdc++.h>
using namespace std;
bool caps(string s) {
return (int) s[0] < 97;
}
int main() {
string s;
map<string, set<string> > m;
set<string> ss;
string prev = "";
while(getline(cin, s)) {
// cout << s << endl;
if(s.compare("0")==0) return 0;
if(s.compare("1") == 0) {
if(m.find(prev)==m.end())m[prev] = 0;
vector<pair<int, string> > v;
for(auto const &p : m) {
v.push_back(make_pair(-p.second.size(), p.first));
}
sort(v.begin(), v.end());
for(auto const &p : v) {
printf("%s %d\n", p.second.c_str(), -p.first);
}
m.clear();
ss.clear();
} else {
if (caps(s)) {
prev = s;
} else {
if(ss.find(s)==ss.end()) {
ss.insert(s);
m[prev].insert(s);
}else {
for(auto const &p : m) {
for(auto it = p.second.begin(); it != p.second.end(); ++it) {
if((*it).compare(s) == 0) {
p.second.erase(it);
}
}
}
}
}
}
}
}