http://acm.hdu.edu.cn/showPRoblem.php?pid=1004
利用map容器可以很容易的解决,同样也可以考虑结构体或者二维数组的方法,有兴趣的可以自己实现一下。
#include<iostream>#include<map>using namespace std;int main(){ int n,max; map<string , int> ballon; string color; string MaxColor; while(cin>>n) { if(n==0) { return 0; } ballon.clear(); for(int i=0;i<n;i++) { cin>>color; ballon[color]++; } map<string, int>::iterator it; max=0; for(it=ballon.begin();it!=ballon.end();it++) { if(it->second>max) { max = it->second; MaxColor = it->first; } } cout<<MaxColor<<endl; }}注意:记得每次进行操作之前先把容器清空,否则上次运行的结果会影响下一次的运算。
新闻热点
疑难解答