B - Let the Balloon Rise
Time Limit:1000MS MemoryLimit:32768KB 64bit IO Format:%I64d& %I64u
Submit Status Practice HDU 1004
Appoint description:
Description
Contest timeagain! How excited it is to see balloons floating around. But to tell you asecret, the judges' favorite time is guessing the most popular problem. Whenthe contest is over, they will count the balloons of each color and find theresult.
This year, they decide to leave this lovely job to you.
Input
Input containsmultiple test cases. Each test case starts with a number N (0 < N <=1000) -- the total number of balloons distributed. The next N lines contain onecolor 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 beprocessed.
Output
For each case,print the color of balloon for the most popular problem on a single line. It isguaranteed that 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
import java.util.*;
class balloon{
Stringcolor;
int number;
public balloon(){
this.color=color;
this.number=number;
}
}
public classMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scannerin= newScanner(System.in);
while(in.hasNext()){
int n=in.nextInt();
if(n==0)break;
in.nextLine();
balloon[]ball=new balloon[n];
for(inti=0;i<n;i++){
ball[i]=new balloon();
ball[i].color=in.nextLine();
for(intj=0;j<=i;j++)
if(ball[i].color.equals(ball[j].color))ball[j].number++;
}
int ans=0;
Stringt=null;
for(inti=0;i<n;i++){
if(ball[i].number>ans){ans=ball[i].number;t=ball[i].color;}
}
System.out.println(t);
}
}
}