HDOJ 1004Let the Balloon Rise(字符串统计)
2018-01-26 11:41
155 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
5
green
red
blue
red
red
3
pink
orange
pink
0
[align=left]Sample Output[/align]
red
pink
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
5
green
red
blue
red
red
3
pink
orange
pink
0
[align=left]Sample Output[/align]
red
pink
#include <iostream> #include<stdio.h> #include<cstring> using namespace std; int main() { int t; while(scanf("%d",&t)&&t!=0) { int i,j; int max=0,n=0; char a[1001][1001]; //可以用二维数组来定义多个字符串 int b[1001]={0}; //memset(b,0,sizeof(b)); for(i=0;i<t;i++) { cin>>a[i]; //输入字符串 b[i]=1; max=1; } for(i=0;i<t-1;i++) { for(j=i+1;j<t;j++) { if(strcmp(a[i],a[j])==0) //strcmp用来比较两个字符串 { b[i]++; if(b[i]>max) { max=b[i]; n=i; } } } } printf("%s\n",a ); } return 0; }
相关文章推荐
- hdoj2017 字符串统计
- C++ hdoj 2017 字符串统计
- HDOJ 1004 字符串处理(字符串统计)
- hdoj 字符串统计
- hdoj 2027 统计元音 (字符串)
- HDOJ 2017 字符串统计
- Hdoj2017_字符串统计
- HDOJ 1004(字符串分类统计)
- HDOJ 2017 字符串统计
- hdoj-2017-字符串统计(解题报告)
- HDOJ 2017 字符串统计
- HDOJ2017 字符串统计
- hdojHPU-ACM大一暑期培训练习题1-1 1001字符串统计
- HDOJ-1251 统计难题 字典树的应用-----统计一组字符串中某前缀出现次数(字典树第一类应用),
- hdoj-2030 汉字统计【字符串&&水】
- HDOJ 2017 字符串统计
- hdoj 2017 字符串统计 (水)
- hdoj 2030 汉字统计 (字符串)
- HDOJ1004 Let the Balloon Rise(字符串——次数统计)
- HDOJ 2017 字符串统计