现在的位置: 首页 > 综合 > 正文

Let the Balloon Rise

2012年05月19日 ⁄ 综合 ⁄ 共 1483字 ⁄ 字号 评论关闭

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
#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>
int maxindex(int *p,int n)
{
int i;
int tem;
int index=0;
tem
=p[0];
for(i=0;i<n;i++)
{
if(tem<=p[i])
tem
=p[i];
}
for(i=0;i<n;i++)
{
if(tem==p[i])
{
index
=i;
}
}
return index;
}
void main()
{
int n;
int i=0;
int j=0;
char *p[1000];
int level=0;
char *save[1000];

int cal[1000]={0};
int index=-1;
for(i=0;i<1000;i++)
{
save[i]
=(char*)malloc(sizeof(char)*20);
}
while(scanf("%d",&n)&&n!=0)
{
index
++;

for(i=0;i<n;i++)
{
p[i]
=(char*)malloc(sizeof(char)*20);
scanf(
"%s",p[i]);
}
for(i=0;i<n;i++)
cal[i]
=0;

for(level=0;level<n;level++)
{
for(j=level+1;j<n;j++)
if(!strcmp(p[level],p[j]))
cal[level]
++;

}
strcpy(save[index],p[maxindex(cal,n)]);
for(i=0;i<n;i++)
{
free(p[i]);
p[i]
=NULL;
}
}

for(i=0;i<=index;i++)
printf(
"%s\n",save[i]);



}

red
pink

 

Author
WU, Jiazhi
 

Source

抱歉!评论已关闭.