纯粹是为了用下HashMap 写Java还真不习惯,狂查API ~~93MS import java.util.*; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); String[] s= new String[1001]; int[] times;//=new int[1001]; int n, i, j; String v; HashMap<String, Integer> hmp;//=new HashMap<String, Integer>(); while(cin.hasNext()) { n=cin.nextInt(); if(n==0) break; times=new int[n+1]; hmp=new HashMap<String, Integer>(); for(i=0,j=0; i<n; i++) { v=cin.next(); if(hmp.get(v)!=null) { int k=hmp.get(v).intValue(); //System.out.println(v+k); times[k]++; } else{ hmp.put(v,Integer.valueOf(++j)); //System.out.println(v+j); s[j]=v; times[j]++; } } int max=-1, mi=0; for(i=1; i<=j; i++) { //System.out.println(i+s[i]+times[i]); if(times[i]>max) { max=times[i]; mi=i;} } System.out.println(s[mi]); } } }