杭电HOJ 1004 Let the Balloon Rise

import java.util.Scanner;
public class Main{
 public static void main(String[]args){
 Scanner cin=new Scanner(System.in);
 while(cin.hasNext()){

 int a=cin.nextInt();
 if(a==0||a<0||a>1000)break;
 //if(a>1000)a=1000;
 String[]s=new String[a];
 for(int i=0;i<a;i++){
 String tem=" ";
 tem=cin.next();
 if(tem.length()>15){
 
  s[i]=tem.substring(0,15);
}
 else //不要忘了加else!!否则提交不通过
 s[i]=tem;  
 
 }

 int temp,max;
 max=temp=0;
 String str=" ";
for(int i=0;i<a;i++){
 
 if(s[i]==" ")continue;
 temp=0;
 for(int j=i+1;j<a;j++){
 
 if(s[i].equals(s[j])){
 temp++;s[j]=" ";}
 
}
 if(temp>max)
 {
  max=temp;
  str=s[i];
  }

 

}//end for
if(str.equals(" "))System.out.println(s[0]);
else//别忘了加else否则提交不通过!!
System.out.println(str);

}//end while

}
}

猜你喜欢

转载自blog.csdn.net/lollo01/article/details/52994769