题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
用STL 中的 Map 写的
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #include <map> 7 using namespace std; 8 9 map<string, int> ballon; 10 string tmp; 11 12 int main() 13 { 14 int i, j, n; 15 while (cin >> n && n) 16 { 17 ballon.clear(); 18 for (i = 0; i < n; i++) 19 { 20 cin >> tmp; 21 ballon[tmp]++; 22 } 23 map<string, int>::iterator iter, poi; 24 int maxp = 0; 25 for (iter = ballon.begin(); iter != ballon.end(); iter++) 26 { 27 if (maxp < iter->second) 28 { 29 maxp = iter->second; 30 poi = iter; 31 } 32 // cout << iter->first << " " << iter->second << endl; 33 } 34 cout << poi->first << endl; 35 } 36 return 0; 37 38 }