Let the balloon rise

Source: Internet
Author: User

Problem descriptioncontest 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.

Inputinput 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.

 

Outputfor 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

#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

 

AuthorWU, Jiazhi 

SourceZJCPC2004

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.