HDOJ 1004 Let the Balloon Rise

題目:http://acm.hdu.edu.cn/showproblem.php?pid=1004

import java.io.*;
import java.util.*; 

public class Main{
	public static void main(String[] args){
		Scanner cin = new Scanner(System.in);		
		while(cin.hasNext()){
			int n = cin.nextInt();
			if(n==0){
			    break;
			}
			n++; //'\0'
			String[] a = new String[n];
			String[] b = new String[n];
			int[] c = new int[n]; //記錄出現次數 
			int max=1,id=1;
			
			for(int i=0;i<n;i++){
				a[i] = cin.nextLine();
				b[i] = a[i];
			}
			
			for(int i=0;i<n;i++){
			    for(int j=i;j<n;j++){
				if(b[i].equals(a[j]))
				    c[i]++;
				}		
			    if(c[i]>max){
			    	max=c[i];
			    	id=i;
			    }
			}
			
		        System.out.println(a[id]);			
		}//end while
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章