1. 程式人生 > >PAT乙級(Basic Level)真題 >挖掘機技術哪家強

PAT乙級(Basic Level)真題 >挖掘機技術哪家強

題目描述
為了用事實說明挖掘機技術到底哪家強,PAT組織了一場挖掘機技能大賽。現請你根據比賽結果統計出技術最強的那個學校。

輸入描述:
輸入在第1行給出不超過105的正整數N,即參賽人數。隨後N行,每行給出一位參賽者的資訊和成績,包括其所代表的學校的編號(從1開始

連續編號)、及其比賽成績(百分制),中間以空格分隔。

輸出描述:
在一行中給出總得分最高的學校的編號、及其總分,中間以空格分隔。題目保證答案唯一,沒有並列。

輸入例子:
6

3 65

2 80

1 100

2 70

3 40

3 0

輸出例子:
2 150

程式碼如下:

import java.util.*;
public
class PAT1023 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int N = in.nextInt(); HashMap<String,Integer> map = new HashMap<>(); String maxa = ""; Integer maxb = 0; for
(int i =0;i<N;i++){ String a = in.next(); Integer b = in.nextInt(); //maxa = a; if(map.containsKey(a)){ b = map.get(a)+b; map.remove(a); map.put(a, b); } else{ map.put(a, b); } if
(b>=maxb){ maxa = a; maxb = b; } } System.out.println(maxa + " " + maxb); } }