Codeforcers #42 (div2) A "Football"

問題:http://www.codeforces.com/contest/43/problem/A

ラクティス.

得点したチームのリストが与えられるので最高得点のチームを出力する.

import java.util.*;
import java.util.Map.Entry;

public class A_Football {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Map<String, Integer> points = new HashMap<String, Integer>();
		for (int t = s.nextInt(); t-- > 0;) {
			String team = s.next();
			Integer goals = points.get(team);
			if (goals == null) {
				goals = 0;
			}
			points.put(team, goals + 1);
		}
		int max = Collections.max(points.values());
		for(Entry<String, Integer> point : points.entrySet()){
			if(point.getValue().equals(max)){
				System.out.println(point.getKey());
				return;
			}
		}
		
	}
}

練習がてらpythonでも書いてみた.

import sys
input()
m={}
for x in sys.stdin:m[x]=m.get(x,0)+1
print sorted(m.items(),key=lambda(k,v):v,reverse=True)[0][0],