我是靠谱客的博主 年轻洋葱,最近开发中收集的这篇文章主要介绍Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )Let the Balloon Rise,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述



原题链接



题目:

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.
 

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
 

Sample Output
red pink
 

     需要对字符串进行处理,并记录各个字符串出现的次数,和最大数所在的字符串的位置 ( 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("%sn",str[flag]);
}
return 0;
}


最后

以上就是年轻洋葱为你收集整理的Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )Let the Balloon Rise的全部内容,希望文章能够帮你解决Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )Let the Balloon Rise所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部