水题,java里的map练手
import java.util.*; import java.math.*; public class Main{ public static void main(String ss[]) { Scanner sc = new Scanner( System.in ); while( sc.hasNext() ) { int tot = sc.nextInt(); String tmp = ""; if( tot == 0 ) break; HashMap<String, Integer> mp = new HashMap<String, Integer>(); while( (tot--) > 0 ) { tmp = sc.next(); int x; if( !mp.containsKey( tmp ) ) x = 0; else x = mp.get(tmp).intValue() + 1; mp.put( tmp, x ); } Set <String> s = mp.keySet(); String ans = ""; int maxx = -1; for( String str : s ) { int x = mp.get(str).intValue(); if( x > maxx ) { maxx = x; ans = str; } } System.out.println( ans ); } } }