HDOJ--1004

来源:互联网 发布:文华日内期货模型源码 编辑:程序博客网 时间:2024/06/11 04:26

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 95873    Accepted Submission(s): 36568


Problem 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
 


这题就是让你找到哪种气球的数量最多,并输出数量最多的气球的颜色。

还是一行一行的搜索并记录吧,你可以一边输入一边搜索,如果相同就在对应的位置上计数器加上1即可,然后就是简单的比大小输出相应位置的气球了。

以下是AC代码:

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int main(){        int n,i,j,temp;    while(scanf("%d",&n)==1 && n!=0)    {        getchar();        int max=0;        int b[1010];        char a[1010][20];        memset(b,1,sizeof(b));        for(i=1;i<=n;i++)        {            gets(a[i]);            for(j=1;j<i;j++)            {                if(!strcmp(a[j],a[i]))                {                    b[j]++;                    break;                }            }        }        for(i=1;i<=n;i++)        {            if(b[i]!=1 && b[i]>max)            {                max=b[i];                temp=i;            }        }        printf("%s\n",a[temp]);    }    return 0; } 


0 0