容器用起来还是很方便的。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int num;
while(cin >> num && num)
{
vector<string> popular;
while(num--)
{
string color;
cin >> color;
popular.push_back(color);
}
int maxnum = 0,num = 0;
string popu;
for(vector<string>::iterator itbegin = popular.begin();itbegin != popular.end();itbegin++)
{
num = 0;
for(vector<string>::iterator it = itbegin;it != popular.end();it++)
{
if(*it == *itbegin)
num ++;
}
if(num > maxnum)
{
maxnum = num;
popu = *itbegin;
}
}
cout << popu << endl;
}
return 0;
}