杭电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.
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.
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
- 杭电ACM-HDU1004-Let the Balloon Rise
- HDU1004 Let the Balloon Rise
- HDU1004--Let the Balloon Rise
- HDU1004 Let the Balloon Rise
- HDU1004:Let the Balloon Rise
- hdu1004 Let the Balloon Rise
- hdu1004 Let the Balloon Rise
- hdu1004 Let the Balloon Rise
- hdu1004 Let the Balloon Rise
- hdu1004 - Let the Balloon Rise
- Hdu1004 Let the Balloon Rise
- HDU1004 Let the Balloon Rise
- hdu1004 Let the Balloon Rise
- HDU1004 Let the Balloon Rise
- hdu1004 -Let the Balloon Rise
- hdu1004 Let the Balloon Rise
- Let the Balloon Rise(杭电ACM 1004)
- 杭电acm 1004 (Let the Balloon Rise)
- 在线数学函数图形和在线数据结构演示
- MFC消息种类
- Hibernate中 Hql语句中包含中文 无法查询到结果的解决办法
- VBS脚本教程:连续的创建文件
- Hibernate不同版本创建SessionFactory
- 杭电ACM-HDU1004-Let the Balloon Rise
- Android属性动画分析
- VHDL状态机
- PHP Twig模版的tags详解(中文)
- Java增强for循环 (java中的冒号)
- oracle读取char(2)字符型数据
- 纽约大学Yann LeCun深度学习
- 站在巨人的肩膀上,C++开源库大全
- 编译内核模块之 Makefile