1004

来源:互联网 发布:孕囊数据两个一样 编辑:程序博客网 时间:2024/05/20 23:07
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
 


很简单一个题目

#include <IOSTREAM>using namespace std;#define MAX_SIZE 1000int main(){int n,i,j,max,sub;char col[16];while(cin>>n && n!=0){int count[MAX_SIZE];char colour[MAX_SIZE][20];int size=0;max=sub=0;for (i=0;i<n;i++){cin>>col;for (j=0;j<size;j++){if (strcmp(colour[j],col)==0){count[j]++;break;}}if (j==size){strcpy(colour[j],col);count[j]=1;size++;      //由于自己粗心,最开始忘了这句!}if(count[j]>max){max=count[j];sub=j;}}cout<<colour[sub]<<endl;}return 0;}



原创粉丝点击