设为首页 加入收藏

TOP

hdu 1004
2017-10-12 17:39:37 】 浏览:1303
Tags:hdu 1004

自从   暑假 ACM集训之后就再也没有碰过  ACM了   以前说出去的话都是泼出去的水啊  哈哈哈  

水一道题啊   一年过去了   

 

 

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
 
 
思路就是:一个字符型二维数组用来存颜色,一个一维整数型数组用了存颜色出现的次数。之后再拿第一个颜色扫一遍,遇见相同的count++,再拿第二个颜色扫一遍,这个用两个for语句。        菜的抠脚啊     水不出来还是抄到其他人的思路的......
 
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     int n,max,i,j;
 6     char a[1000][15],b[1000];
 7     while(scanf("%d",&n)&&n)
 8     {
 9         for(i=0; i<n; i++)
10         {
11             scanf("%s",&a[i]);
12             b[i]=0;
13         }
14         for(i=0; i<n; i++)
15         {
16             for(j=i+1;j<n;j++)
17                 if(strcmp(a[i],a[j])==0)
18                     b[i]++;
19         }
20         max=0;
21         for(i=0;i<n;i++)
22             if(max<b[i])
23                 max=i;
24         printf("%s\n",a[max]);
25     }
26     return 0;
27 }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于Linux动态库的相关知识 下一篇hdu 1005

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目