杭电ACM-HDU1004-Let the Balloon Rise

来源:互联网 发布:收看日本电视台软件 编辑:程序博客网 时间:2024/06/05 16:10

题目来自杭电ACM: acm.hdu.edu.cn

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 93510    Accepted Submission(s): 35712



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
 

Author
WU, Jiazhi
 

Source
ZJCPC2004

代码如下:

#include <stdio.h>#include <string.h>#define N 1010int count[N];char ballon[N][16];int main(){int n, i, j;while (1){scanf("%d", &n);if (n == 0){break;}gets(ballon[0]);for (i = 1; i <= n; ++i){gets(ballon[i]);}int max = 1, position = 1;for (i = 1; i <= n; ++i){count[i] = 0;for (j = i; j <= n; ++j){if (strcmp(ballon[i], ballon[j]) == 0){count[i]++;if (count[i] > max){max = count[i];position = i;}}}}printf("%s\n", ballon[position]);}return 0;}

这是一个较为简单的考察字符串的题目,通过头文件string.h中的strcmp函数来判断字符串是否相同。

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 妹子内裤被看了怎么办 都已婚却相爱了怎么办 喝了很烫的水怎么办 金毛幼犬不吃狗粮怎么办 4孩子受凉了呕吐怎么办 尿多是什么原因造成的怎么办 5岁宝宝老尿床怎么办 五岁了还尿床怎么办 2岁宝宝晚上尿床怎么办 胃疼腹泻稀水怎么办 网购成瘾怎么办 知乎 军人被警察打了怎么办 对高院再审不服怎么办 对高院判决不服怎么办 白色砂锅烧黑了怎么办 手机被偷关机了怎么办 狗被眼镜蛇咬了怎么办 穿高跟鞋脚趾头长茧怎么办 穿皮鞋脚底板疼怎么办 鞋子穿了脚趾痛怎么办 脚被鞋子磨肿了怎么办 脚趾磨出茧子怎么办疼 脚掌长茧走路疼怎么办 脚底磨出茧子疼怎么办 手指上写字有茧怎么办 写字磨的茧子疼怎么办 脚上的大脚骨疼怎么办 脸特别烫 又红怎么办 6岁宝宝发音不准怎么办 3岁宝宝发音不准怎么办 5岁宝宝发音不准怎么办 4岁宝宝发音不准怎么办 被螃蟹夹出血了怎么办 苹果6主板坏了怎么办 键盘掉了一个键怎么办 汽车屏幕砸坏了怎么办 电视的屏幕坏了怎么办 高三孩子早恋该怎么办 高一早恋家长该怎么办 高二早恋家长该怎么办 200斤新娘抱不动怎么办