今天做1004,因为之前没用过map,加上很少用C++, 因为又去翻看map的使用,发觉C++真是很神奇嗯!!不过但是依然不是很会,学习C++仍需努力。以下代码有借鉴成分,还请高手们勿喷~~
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;
//struct Color{
// int time ; //出现次数
// char color[16] ;
//};
int main(){
int num;
int i;
while ((scanf("%d", &num) != EOF)&&(num != 0)){
map<string,int> s;
string str;
char instring[1001];
for(i = 1; i <= num ; i++){
scanf("%s",instring) ;
s[instring]++ ;
}
int max = 0;
for(map<string , int>::iterator it = s.begin(); it!=s.end(); it++){
if(it->second >max){
max = it->second ;
str = it->first ;
}
}
cout<<str<<endl;
//getchar();
//printf("%s\n",str);
}
return 0;
}