PAT 1032 挖掘机技术哪家强
#include <iostream>
#include <stdio.h>
#include <string.h>
#define maxn 100005
using namespace std;
int main() {
int players[maxn], n, school, score;
cin >> n;
memset(players, 0, sizeof(players));
for (int i = 0; i < n; i++) {
cin >> school >> score;
players[school] += score;
}
int ans =0, sum =0;
for (int i = 0; i <=n; i++) {
if(players[i] > sum) {
ans = i;
sum = players[i];
}
}
printf("%d %d\n", ans, sum);
return 0;
}
错误点:
- 10^5应该定义成100005,中间四个零
- 第二个循环需要指到n(≤n),因为学校的编号是1~n,注意细节!
- 如果只有两个数字,不需要用结构体