#include
#include
#include
using namespace std;
map mp;
int main()
{
int n;
while (cin>>n, n!=0)
{
string s,p;
int mx=0;
for (int i=0;i
{
cin>>s;
if (mp.find(s)==mp.end())
{
mp[s]=1;
if (1>mx)
{
mx=1;
p=s;
}
}
else
{
mp[s]++;
if (mp[s]>mx)
{
mx=mp[s];
p=s;
}
}
}
cout << p << endl;
}
}

麻烦帮我解释一下这个程序吧,谢谢了
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- shen_wei 2017-08-04 06:08关注
map<string,string> mp; //定义应该如此。。 string s,p; int mx = 0; while(1) { cin >> s; if (mp.find(s) == mp.end()) // 查找map的字符串,但是 s 新输出的,除非有输入相同的字符串,否则一致为ture { mp[s]=1; if (1>mx) // { mx=1; p=s; } } else { //mp[s].; if(mp[s].length() > mx) // { mx = mp[s].length(); p=s; } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报