zoj2104

思路:使用map<string,int> mp
字符串的hash

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	map<string,int> mp;
	int n;
	char s[20];
	string str;
	map<string,int>::iterator it,it2;
	while(scanf("%d",&n)!=EOF&&n!=0){
		mp.clear();
		for(int i=0;i<n;i++){
			scanf("%s",s);
			str=s;
			if(mp.find(str)!=mp.end())
					mp[str]+=1;
			else
					mp[str]=1;	
		}
		it2=mp.begin();
		for(it=mp.begin();it!=mp.end();it++){
			if(it->second > it2->second)
					it2=it;
		}
		printf("%s\n",it2->first.c_str());
	}
	return 0;
}
全部评论

相关推荐

09-19 12:15
门头沟学院 Java
迷茫的大四🐶:这下是真的打牌了,我可以用感谢信和佬一起打牌吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务