题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104
这道题主要用了multiset使程序设计简单了很多
#pragma warning(disable:4786)
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
multiset<string> s;
string str;
int i,count,max,tmp;
multiset<string>::iterator tar,ib,ie;
while(cin >> count && count != 0)
{
for(i = 0;i < count;++i)
{
cin >> str;
s.insert(str);
}
max = 0;
ie = s.end();
for(ib = s.begin();ib != ie;++ib)
{
tmp = s.count(*ib);
if(tmp > max)
{
max = tmp;
tar = ib;
}
}
cout << *tar << '/n';
s.clear();
}
return 0;
}