HDU 1004. map的相关使用
原题链接
简单
作者:
史一帆
,
2021-05-21 20:57:12
,
所有人可见
,
阅读 145
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
typedef pair<string, int> PSI;
int main()
{
int n;
while (cin >> n && n)
{
map<string, int> mp;
map<string, int>::iterator it;
map<string, int>::iterator ans;
for (int i = 0; i < n; i ++ )
{
string str;
cin >> str;
it = mp.find(str);
if (it == mp.end()) mp.insert(PSI(str, 1));
else mp[str] ++ ;
}
int max = 0;
for (it = mp.begin(); it != mp.end(); it ++ )
if (it -> second > max) max = it -> second, ans = it;
cout << ans -> first << endl;
}
return 0;
}