HDU

来源:互联网 发布:佛山网络推广 招聘 编辑:程序博客网 时间:2024/06/15 15:06

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 126802    Accepted Submission(s): 50120


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
5greenredblueredred3pinkorangepink0
 

Sample Output
redpink


题意:给定一堆气球 问里面个数最多的是哪个颜色


思路:每输入一个气球 从前到后遍历 是新的颜色就添加 旧的就直接个数+1


#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>using namespace std;int main(){int n;while(scanf("%d",&n)!=EOF&&n!=0){getchar();char sent[n][20],word[20];int i,j,max=0,count=1,k,flag=0,num[n];memset(num,0,sizeof(int)*n);scanf("%s",sent[0]);for(i=1;i<n;i++){flag=0;scanf("%s",word);for(j=0;j<count;j++){if(strcmp(sent[j],word)==0){num[j]++;flag=1;break;}}if(flag==0){strcpy(sent[count],word);count++;}}for(i=0;i<count;i++){if(num[i]>max){max=num[i];k=i;}}printf("%s\n",sent[k]);}return 0;}