统计字符串,用了map。 #include <stdio.h> #include <map> #include <string.h> #include <string> #include <iostream> using namespace std; map<string,int> s; int main() { int n; while(scanf("%d",&n),n) { int len; string str; s.clear(); for(int i=0; i < n; i++ ) { cin >> str; s[str]++; } int max = -1; map<string,int>::iterator iter; for(iter = s.begin(); iter != s.end(); iter++) { if(iter->second > max) max = iter->second; } for(iter = s.begin(); iter != s.end(); iter++) { if(max == iter->second) cout<<iter->first<<endl; } } return 0; }