现在的位置: 首页 > 综合 > 正文

hdu 1004 Let the Balloon Rise map

2019年02月20日 ⁄ 综合 ⁄ 共 514字 ⁄ 字号 评论关闭

水题,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 );
		}
	}
}

抱歉!评论已关闭.