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 }