HDU--1004 Let the Balloon Rise

Posted ⊙∽⊙Perseverance

tags:

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

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
题意:求出现次数最多的颜色
AC代码:
 1 #include<cstdio>
 2 #include<cstring>
 3 struct Vote
 4 {
 5     char c[20];
 6 }p[1005];
 7 int main()
 8 {
 9     int n;
10     while(scanf("%d",&n)!=EOF&&n)
11     {
12         for(int i=0;i<n;i++)
13         {
14             scanf("%s",p[i].c);
15         }
16         int max=0,mark,num=1;
17         for(int i=0;i<n;i++)
18         {
19             for(int j=i+1;j<n;j++)
20             {
21                 if(strcmp(p[i].c,p[j].c)==0)   //如果只有第一个字符相同可以写成,p[i].c[0]==p[j].c[0];是结构体里面字符串的第一个字符,以前多用的是二维数组,很少用结构体 
22                 {
23                     num++;
24                 }
25             }
26             if(num>max)
27             {
28                 max=num;
29                 mark=i;
30             }
31         }
32         printf("%s\n",p[mark].c);
33     }
34     return 0;
35 }

 

 

以上是关于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

HDU 1004 Let the Balloon Rise map