杭电ACM1004问题
1个回答
展开全部
#include <map>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
map<string,int> strMap;
while(cin>>n && n)
{
strMap.clear();
for(int i = 0; i < n; ++ i)
{
cin>>str;
int t = strMap[str];
if(t)
{
strMap[str] ++;
}
else
{
strMap[str] = 1;
}
}
int nTemp;
string strTemp;
map<string,int>::const_iterator it = strMap.begin();
nTemp = it->second;
strTemp=it->first;
while(it != strMap.end())
{
if(it->second > nTemp)
{
nTemp = it->second;
strTemp = it ->first;
}
it ++;
}
cout<<strTemp<<endl;
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
map<string,int> strMap;
while(cin>>n && n)
{
strMap.clear();
for(int i = 0; i < n; ++ i)
{
cin>>str;
int t = strMap[str];
if(t)
{
strMap[str] ++;
}
else
{
strMap[str] = 1;
}
}
int nTemp;
string strTemp;
map<string,int>::const_iterator it = strMap.begin();
nTemp = it->second;
strTemp=it->first;
while(it != strMap.end())
{
if(it->second > nTemp)
{
nTemp = it->second;
strTemp = it ->first;
}
it ++;
}
cout<<strTemp<<endl;
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询