这题主要用Map来实现
#include <iostream> #include <map> #include <cstring> using namespace std; int main() { // freopen("1.txt","r",stdin); // freopen("2.txt","w",stdout); int n; map<string,int>m; string str; while(scanf("%d",&n)==1 && n) { m.clear(); for(int i=0;i<n;i++) { cin >> str; m[str]++; } map<string,int>::iterator p,q; int max=-1; for(p=m.begin(); p!=m.end(); p++) if(p->second > max) { max=p->second; q=p; } cout << q->first << endl; } return 0; }