PAT B1047 编程团体赛(C++)

PAT甲级目录 | PAT乙级目录

题目描述

B1047 编程团体赛

解题思路

利用 hash 数组记录每个队伍的累计分数,同时更新最大分数以及对应的队伍编号。

代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cstdio>
int main(){
int team[1005] = {0}, N, max_score = -1, max_id;
scanf("%d", &N);
for(int i = 0; i < N; i++){
int id, x, score;
scanf("%d-%d %d", &id, &x, &score);
team[id] += score;
if(team[id] > max_score){
max_score = team[id];
max_id = id;
}
}
printf("%d %d\n", max_id, max_score);
return 0;
}