-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreqstring.cpp
More file actions
37 lines (34 loc) · 802 Bytes
/
freqstring.cpp
File metadata and controls
37 lines (34 loc) · 802 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
#include <bits/stdc++.h>
using namespace std;
typedef map<int, string> M;
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
map<string , int> m;
int max1 = INT_MIN, max2 = INT_MIN;
string s1;
for(int i = 0; i < n; i++) {
string s;
cin>>s;
m[s]++;
if(m.at(s) > max1) {
max1 = m.at(s);
}
}
map<string , int>::iterator it;
for (it = m.begin(); it != m.end() ; ++it)
{
if(it->second != max1) {
if(it->second > max2) {
max2 = it->second;
s1 = it->first;
}
}
}
cout<<s1<<endl;
}
return 0;
}