Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )
来源:互联网 发布:华为it应用技术工程师 编辑:程序博客网 时间:2024/06/05 11:50
原题链接
题目:
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89088 Accepted Submission(s): 33718
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
需要对字符串进行处理,并记录各个字符串出现的次数,和最大数所在的字符串的位置 ( flag );
AC代码:
#include<stdio.h>#include<string.h>#include<stdlib.h>int main(){int n,max[1001];char str[1001][100];while(scanf("%d",&n)&&n){memset(max,0,sizeof(max));int in,out;for(in=0;in<n;in++)//输入 n 个字符串;{scanf("%s",&str[in]);}for(in=0;in<n;in++)//从第一个字符串开始到最后一个字符串比较是否相同;for(out=0;out<n;out++)//每次都扫描所有的字符串;{if(strcmp((str[out]),(str[in]))==0)max[in]++;//记录每个字符串数目}int big=-1,flag;//big用于找出最大的出现次数;flag记录位置;for(in=0;in<n;in++)//寻找最大次数;{if(big<max[in]){big=max[in];flag=in;}}printf("%s\n",str[flag]);}return 0;}
0 0
- Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )
- HDOJ 1004 Let the Balloon Rise(字符串)
- hdoj 1004 Let the Balloon Rise(字符串比较问题)
- hdoj 1004 Let the balloon rise (字符串处理问题)
- [字符串][第二阶段-字符串处理][HDOJ-1004]Let the Balloon Rise
- HDOJ - 1004 - Let the Balloon Rise(字符串)
- HDOJ 1004 Let the Balloon Rise (map)
- HDOJ-1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- hdoj 1004 Let the Balloon Rise
- hdoj.1004 Let the Balloon Rise 20140726
- HDOJ Let the Balloon Rise 1004
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise(水题)
- 【HDOJ】【1004】Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- I2C总线和SPI总线
- mybatis 实现关联查询的一对多和多对多查询
- 方法内部lambda表达式中若用到变量,若在方法内lambda外,则只能为final,或者定义为全局变量
- 好压报错“启动参数错误,程序即将退出!”
- java 使用freemarker生成word
- Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )
- addChildViewController
- Redis 配置文件说明
- 如何用textview设置drawableLeft属性
- storm基础框架分析
- Lowest Common Ancestor of a Binary Tree
- UVa 11538 Chess Queen 象棋中的皇后
- HDU 5308 I Wanna Become A 24-Point Master
- Android-对ListView的Adapter的一种简单封装