Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
5 green red blue red red 3 pink orange pink 0
red pink
map水题
代码如下:
//
// main.cpp
// A - stl 的 map
//
// Created by 徐智豪 on 2017/3/28.
// Copyright © 2017年 徐智豪. All rights reserved.
//
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
int n;
while(cin>>n&&n)
{
map<string,int> thecolor;
string color;
while(n--)
{
cin>>color;
thecolor[color]++;
}
map<string,int>::iterator p,m;
for(p=m=thecolor.begin();p!=thecolor.end();p++)
{
if(p->second>m->second)
{
m=p;
}
}
cout<<m->first<<endl;
}
return 0;
}