PKU : 2153 - Rank List
問題概要
http://poj.org/problem?id=2153
Li Mingさんを含むN人の生徒がいます.
M回テストを行っていって, 各テストで生徒iが点数をとると, 生徒iの点数合計に足しこまれます.
各テストを終えた後の, Li MingさんのランクをM回出力してください.
プログラム
public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); HashMap<String,Integer> score = new HashMap<String,Integer>(); score.put("Li Ming",0); for(int i=0;i<n;i++){ String s = br.readLine(); score.put(s,0); } int m = Integer.parseInt(br.readLine()); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ String[] s = br.readLine().split(" ",2); score.put(s[1],score.get(s[1])+Integer.parseInt(s[0])); } int now = score.get("Li Ming"); int rank = 1; for(String x : score.keySet()) if(now < score.get(x)) rank++; System.out.println(rank); } }