题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
用map做较为方便
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, int> m;
int n;
while (cin >> n && n) {
string s;
while (n--) {
cin >> s;
m[s]++;
}
map<string, int>::iterator it = m.begin();
int max = it->second;
string s1 = it->first;
for (; it != m.end(); it++) {
if (it->second > max) {
max = it->second;
s1 = it->first;//记住气球最大值的颜色
}
}
cout << s1 << endl;
m.clear();//用完清空就完事了,因为这个wrong了好多次
}
}