HDU 1004 Let the Balloon Rise
来源:互联网 发布:淘宝代付有限额吗 编辑:程序博客网 时间:2024/05/21 19:49
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
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output
red
pink
感言:很简单的一个问题,但是我做的时候竟然没想到用2维字符数组,太失败了,应以此为戒,思维不要太局限了
pink
感言:很简单的一个问题,但是我做的时候竟然没想到用2维字符数组,太失败了,应以此为戒,思维不要太局限了
题目的大意为统计相同颜色气球的气球。对于ACM题,有些时候实在无法理解题意时就应该看给出的测试数据
#include <stdio.h>
#include <string.h>
int main(){
int n, i, j, t, max, num[1000];
char color[1000][16];
while(scanf("%d", &n) != EOF)
{
if(n==0)break;
num[0]=0;
scanf("%s", color[0]);
for(i=1; i <n; i++)
{
num[i]=0;
scanf("%s", color[i]);
for(j=0; j <i-1; j++)
if(strcmp(color[i],color[j])==0) num[i]+=1;
}
max=num[0];
t=0;
for(i=1; i <n; i++)
if(max <num[i]) {max =num[i]; t=i;}
printf("%s\n",color[t]);
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main(){
int n, i, j, t, max, num[1000];
char color[1000][16];
while(scanf("%d", &n) != EOF)
{
if(n==0)break;
num[0]=0;
scanf("%s", color[0]);
for(i=1; i <n; i++)
{
num[i]=0;
scanf("%s", color[i]);
for(j=0; j <i-1; j++)
if(strcmp(color[i],color[j])==0) num[i]+=1;
}
max=num[0];
t=0;
for(i=1; i <n; i++)
if(max <num[i]) {max =num[i]; t=i;}
printf("%s\n",color[t]);
}
return 0;
}
0 0
- 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
- 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
- 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
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise STL
- 灯火阑珊处等你回眸
- HDU 3711 Binary Number
- Android Mainfest配置
- Android中自定义checkbox样式 two
- 嵌入式中通讯协议的设计
- HDU 1004 Let the Balloon Rise
- Android自定义扁平化对话框
- 解决Ubuntu下Sublime text 2的中文输入问题(使用fcitx输入法)
- C++ 中常用数学函数
- 吃鱼胆导致急性肝衰肾衰的患者
- 存储过程中简单事务书写方法
- 搜狗浏览器保存的密码如何查看
- 《歌手2》张杰补位飙高音 邓紫棋夺冠韦唯垫底
- C++内联函数