用Hash表快乐数气球,感觉我的方法非常清楚呀,之前提交不通过竟然是因为没有实现循环输入
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
int a;
while(cin>>a){
if(a==0) return 0;
map<string,int>:: iterator it;
map<string,int>:: iterator color;
map<string,int>:: iterator i;
map<string,int> hashtable;
int max = 0;
for(int k=0;k<a;k++){
string b;
cin>>b;
it = hashtable.find(b);
if(it != hashtable.end()){
hashtable[b] = hashtable[b] + 1;
} else{
hashtable[b] = 1;
}
}
for(i = hashtable.begin();i!= hashtable.end();i++){
if(i->second > max){
color = i;
max = i->second;
}
}
cout<< color->first << endl ;
}
return 0;
}