-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCVOTE.cpp
More file actions
39 lines (38 loc) · 853 Bytes
/
Copy pathCVOTE.cpp
File metadata and controls
39 lines (38 loc) · 853 Bytes
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
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
string name, country;
unordered_map<string, string> name_country;
unordered_map<string, int> country_count, name_count;
cin>>n>>m;
while(n--){
cin>>name>>country;
name_country.insert({name, country});
}
while(m--){
cin>>name;
name_count[name]++;
country_count[name_country[name]]++;
}
for(auto i: country_count){
if(i.second>m){
m = i.second;
country = i.first;
}
else if(i.second==m) country = min(country, i.first);
}
for(auto i: name_count){
if(i.second>n){
n = i.second;
name = i.first;
}
else if(i.second==n) name = min(name, i.first);
}
cout<<country<<"\n"<<name;
return 0;
}