题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1004
map的用法,第一次看见map还能这么用
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<iostream> #include<map> #include<string> using namespace std; int n; string s; int main() { while (cin >> n, n){ map<string, int>a; map<string, int>::iterator b; for (int i = 0; i < n; i++){ cin >> s; a[s]++; } b = a.begin(); int ans=0; string res; for (; b != a.end(); b++){ if (b->second >ans){ ans = b->second; res = b->first; } } cout << res << endl; } return 0; }