-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10420.cpp
72 lines (58 loc) · 1.33 KB
/
10420.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
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<string> countryNames;
vector<int64_t> conquestCount;
void _counting();
void _sorting();
int main() {
int64_t loops = 0;
while (cin >> loops) {
for (int64_t i = 0; i < loops; i++) {
_counting();
}
_sorting();
for (int64_t i = 0; i < countryNames.size(); i++) {
cout << countryNames.at(i) << " " << conquestCount.at(i) << endl;
}
countryNames.clear();
conquestCount.clear();
}
return 0;
}
void _counting() {
string temp;
cin >> temp;
if (countryNames.size() == 0) {
countryNames.push_back(temp);
conquestCount.push_back(1);
} else {
bool found = false;
for (int64_t i = 0; i < countryNames.size(); i++) {
if (temp == countryNames.at(i)) {
found = true;
conquestCount.at(i)++;
}
}
if (found == false) {
countryNames.push_back(temp);
conquestCount.push_back(1);
}
}
getline(cin, temp);
}
void _sorting() {
vector<string> countryNameTemp = countryNames;
vector<int64_t> countryCountTemp = conquestCount;
sort(countryNames.begin(), countryNames.end());
for (int64_t i = 0; i < countryNames.size(); i++) {
for (int64_t j = 0; j < countryNameTemp.size(); j++) {
if (countryNames[i] == countryNameTemp[j]) {
conquestCount[i] = countryCountTemp[j];
}
}
}
}