forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoo.cpp
49 lines (38 loc) · 946 Bytes
/
zoo.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
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
string lastWord(string s) {
int index = s.find_last_of(' ') + 1;
string last = s.substr(index);
for(auto &c : last) {
c = tolower(c);
}
return last;
}
int main() {
int n;
int i = 1;
while(cin >> n && n != 0) {
multiset<string> animals;
vector<string> names;
cin.ignore();
for(int i = 0; i < n; i++) {
string name;
getline(cin, name);
name = lastWord(name);
if(animals.count(name) == 0) {
names.push_back(name);
}
animals.insert(name);
}
sort(names.begin(), names.end());
cout << "List " << i << ":" << endl;
for(auto name : names) {
cout << name << " | " << animals.count(name) << endl;
}
i++;
}
}