Hdoj Title Address: Portal
Let the Balloon Rise Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total submission (s): 104731 Accepted Submission (s): 40328
Problem Description Contest Time again! How excited it was to see balloons floating around. But to tell you a secret, the judges ' favorite time was guessing the most popular problem. When the contest was over, they would count the balloons of each color and find the result.
This is the year that they decide to leave the lovely job to you.
Input input contains multiple test cases. Each test case is starts with a number n (0 < N <=) – 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 lower-case letters.
A test Case with N = 0 terminates the-input and this-test case are not-to-be processed.
Output for each case, print the color of balloon for the most popular problem on a. It is guaranteed this there is a unique solution for each test case.
Sample Input
5 green red Blue Red Red 3 pink Orange Pink 0
Sample Output
Red Pink
Test instructions: Give you a lot of color balloons, want you to find the most frequently the color of the balloon, very simple water problem
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <memory.h>
using namespace std;
int main () {
int n;
while (scanf ("%d", &n) &&n) {
string str[1001];
int result[1001];
string S;
memset (result,0,sizeof (Result));
int index=0,i,j,k;
GetChar ();
for (i=0;i<n;i++) {
getline (cin,s);
int flag=1;
for (j=0;j<index;j++) {
if (str[j]==s) {
result[j]++;
flag=0;
break;
}
}
if (flag) {
str[index]=s;
index++;
}
}
int re=-1;
int temp;
for (k=0;k<index;k++) {
if (result[k]>re) {
re=result[k];
temp=k;
}
}
cout<<str[temp]<<endl;
}
}