hdu-1004 Let the Balloon Rise

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu-1004 Let the Balloon Rise相关的知识,希望对你有一定的参考价值。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004

题目:

Let the Balloon Rise

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


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
5
green
red
blue
red
red
3
pink
orange
pink
0
 

 

Sample Output
red
pink
 
题意概括:
给出N个颜色的气球,输出那种颜色的气球数目最多(输出n个字符串中出现的次数最多的);
解题思路:
通过结构体组判断那个下标的结构体出现的次数最多。
AC代码:
# include <stdio.h>
# include <string.h>

struct{
    char name[50];
    int n,l;
}co[1010];

int main ()
{
    int n,i,j,max,num;
    while(scanf("%d",&n),n)
    {
        getchar();
        for(i=0;i<n;i++)
        {
             gets(co[i].name);
             co[i].l=strlen(co[i].name);
             co[i].n=1;
        }
        max=0;num=0;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                if(co[i].l==co[j].l && strcmp(co[i].name,co[j].name)==0)
                    co[i].n++;
            }
            if(max<co[i].n)
            {
                 max=co[i].n;
                 num=i;
            }
        }
        puts(co[num].name);
    }
    return 0;
}

 

以上是关于hdu-1004 Let the Balloon Rise的主要内容,如果未能解决你的问题,请参考以下文章

HDU--1004 Let the Balloon Rise

HDU1004:Let the Balloon Rise

hdu-1004 Let the Balloon Rise

HDU(1004)Let the Balloon Rise

hdu 1004 Let the Balloon Rise

HDU 1004 Let the Balloon Rise map