#include <map>
#include <string>
#include <iostream>
#include <vector>
#include "stdio.h"
using namespace std;
int main()
{
int n;
map<string, int> ballon;
vector<string> colo;
string temp;
while(scanf("%d",&n)!=EOF&&n!=0)
{
ballon.clear();
for(int i = 0; i< n; i++)
{
cin>>temp;
ballon[temp]++;
}
map<string,int>::const_iterator ite;
int max = -1;
for(ite = ballon.begin();ite != ballon.end();ite++)
{
if(ite->second >max)
{
max = ite->second;
temp = ite->first;
}
}
cout<<temp<<endl;
}
}
算法思路:
题意要求纪录每一种颜色以及出现的次数,然后比较次数,输出最大次数所代表的颜色