Hdu 1004, hdu

Source: Internet
Author: User

Hdu 1004, hdu

I have never touched ACM since the summer ACM training session. I used to talk about it all over the water. Hahaha

A year has passed.

 

 

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 Input5greenredblueredred3pinkorangepink0

 

The idea of Sample Outputredpink is: a two-dimensional 2D array is used to store colors, and a one-dimensional integer array uses the number of times the colors appear. Then, scan the first color, count ++ with the same value, and the second color with two for statements. You can't just copy the course to other people's ideas ......
 1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5     int n,max,i,j; 6     char a[1000][15],b[1000]; 7     while(scanf("%d",&n)&&n) 8     { 9         for(i=0; i<n; i++)10         {11             scanf("%s",&a[i]);12             b[i]=0;13         }14         for(i=0; i<n; i++)15         {16             for(j=i+1;j<n;j++)17                 if(strcmp(a[i],a[j])==0)18                     b[i]++;19         }20         max=0;21         for(i=0;i<n;i++)22             if(max<b[i])23                 max=i;24         printf("%s\n",a[max]);25     }26     return 0;27 }

 

Related Article

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.