-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10420.cpp
52 lines (46 loc) · 1.08 KB
/
P10420.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
#include <iostream>
#include <string>
#include <map>
unsigned int readUInt() {
unsigned int ret = 0;
char w[20];
std::cin.getline(w, 20);
for(int i = 0; i < 20; ++i) {
if(!(w[i] >= '0' && w[i] <= '9'))
break;
ret = ret * 10 + (w[i]-'0');
}
return ret;
}
void readCountryLine(int *cnt, std::map<std::string,unsigned int> &map) {
char w[100];
std::cin.getline(w, 100);
for(int i = 0; true; ++i) {
if(w[i] == ' ') {
w[i] = '\0';
break;
}
}
std::string s(w);
std::map<std::string,unsigned int>::iterator it = map.find(s);
if(it == map.end()) {
unsigned int idx = map.size();
cnt[idx] = 1;
map.insert(std::make_pair(s, idx));
}
else {
cnt[it->second]++;
}
}
int main() {
int lines = readUInt();
int cnt[2000];
std::map<std::string,unsigned int> map;
for(int ignore = 0; ignore < lines; ++ignore) {
readCountryLine(cnt, map);
}
for(std::map<std::string,unsigned int>::const_iterator it = map.begin(); it != map.end(); ++it) {
std::cout << it->first << " " << cnt[it->second] << std::endl;
}
return 0;
}