PAT B1032 挖掘机技术哪家强(C++)

PAT甲级目录 | PAT乙级目录

题目描述

B1032 挖掘机技术哪家强

解题思路

用一个数组记录所有学校的总分,同时更新最大分数及学校id。

代码示例:

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