#include #include #include #include #include #include using namespace std; map ball; int main(){ int n,i,j; string s; //freopen("in.txt","r",stdin); while (scanf("%d",&n)==1 && n!=0){ ball.erase(ball.begin(),ball.end()); //map中旧元素的删除 for (i=1;i<=n;i++){ cin>>s; if (!ball.count(s)) //判断字符串s是否存在,返回1或0;还可以用find(),返回值是map的迭代器 ball[s]=1; //map的赋值可以直接用数组形式 else ball[s]++; } int Max=0; string maxstring; map ::iterator ite=ball.begin();//map迭代器的使用 for (ite=ball.begin();ite!=ball.end();ite++) if (ite->second>Max) { //map中第一个第二个元素用first、second表示 Max=ite->second; maxstring=ite->first; } cout< <