来源:http://acm.hdu.edu.cn/showproblem.php?pid=1004
map的运用
#include<stdio.h>
#include<string>
#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
int judge(string str)
{
map<string,int>::iterator it;
it=m.find(str);
if(it==m.end())return 0;
return 1;
}
int main()
{
int n,count,i,max;
string b;
while(cin>>n&&n)
{
m.clear();
while(n--)
{
cin>>b;
if(judge(b))
{
count=m[b];
m.erase(b);
m[b]=count+1;
}
else
{
m[b]=1;
}
}
max=0;
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
if((it->second)>max)
{
b=it->first;
max=it->second;
}
}
cout<<b<<endl;
}
return 0;
}