K - Let the Balloon Rise

来源:互联网 发布:哈奇森效应 知乎 编辑:程序博客网 时间:2024/06/05 16:36

Description

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.
 

Input

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.
 

Output

For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
 

Sample Input

5greenredblueredred3pinkorangepink0
 

Sample Output

redpink
 

#include <iostream>#include <map>#pragma warning(disable:a786)#include <cstdio>using namespace std;map<string,int>m;int main(){    int n,i;    string color;    while(scanf("%d",&n)&& n)    {        m.clear();        for(i = 0; i < n; i++)        {            cin>>color;            m[color]++;        }        map<string,int>::iterator it;        string color2;        int temp=0;        for(it=m.begin();it!=m.end();it++)        {            if((*it).second>temp)            {                temp=(*it).second;                color2=(*it).first;            }        }        cout<<color2<<endl;    }    return 0;}
题意就是要哪种颜色最受欢迎 就是出现次数最多用map第一个寸颜色 第二个存数量  循环着遍历  最后设置一个变量 来查这个最多的颜色 
0 0
原创粉丝点击