1. 程式人生 > >PAT-乙-1047 1047 程式設計團體賽 (20 分)

PAT-乙-1047 1047 程式設計團體賽 (20 分)

在這裡插入圖片描述 在這裡插入圖片描述

程式碼

#include <iostream>
#include <map>

using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	map<int, int> m;
	int championNum = 0;
	int championScore = 0;
	for(int i=0; i<n; i++) {
		int team, member, score;
		scanf("%d-%d %d", &team, &member, &score);
		if(m[team]) {
			m[team] += score;
		} else {
			m[team] = score;
		}
		if(m[team]>championScore) {
			championNum = team;
			championScore = m[team];
		}
	}
	printf("%d %d\n", championNum, championScore);

	return 0;
}

註解

map的簡單使用。

結果

在這裡插入圖片描述