Let the balloon rise
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 50554 accepted submission (s): 18117
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
Sample outputredpink
1 // define a color [100], 2 after each color input // compare with the previous one if the same num ++ 3 // finally output the largest num 4 # include <iostream> 5 # include <string. h> 6 # include <stdio. h> 7 # include <ctype. h> 8 # include <algorithm> 9 # include <stack> 10 # include <queue> 11 # include <set> 12 # include <math. h> 13 # include <vector> 14 # include <map> 15 # include <deque> 16 # include <list> 17 using namespace STD; 18 int main () 19 {20 int N, I, j, num [1000]; 21 int max = 0, T = 0; 22 char color [2, 1000] [16]; 23 while (scanf ("% d", & N )! = EOF) 24 {25 if (n) 26 {27 num [0] = 0; 28 scanf ("% s", color [0]); 29 for (I = 1; I <n; I ++) 30 {31 num [I] = 0; 32 scanf ("% s", color [I]); 33 for (j = 0; j <I-1; j ++) 34 if (strcmp (color [I], color [J]) = 0) num [I] + = 1; 35} 36 max = 0; 37 T = 0; 38 for (I = 1; I <n; I ++) 39 if (max <num [I]) 40 {41 max = num [I]; 42 T = I;} 43 printf ("% s \ n ", color [T]); 44} 45} 46 Return 0; 47}
View code