1032 挖掘機技術哪家強 (20 分)
爲了用事實說明挖掘機技術到底哪家強,PAT 組織了一場挖掘機技能大賽。現請你根據比賽結果統計出技術最強的那個學校。
輸入格式:
輸入在第 1 行給出不超過 10
5
的正整數 N,即參賽人數。隨後 N 行,每行給出一位參賽者的信息和成績,包括其所代表的學校的編號(從 1 開始連續編號)、及其比賽成績(百分制),中間以空格分隔。
輸出格式:
在一行中給出總得分最高的學校的編號、及其總分,中間以空格分隔。題目保證答案唯一,沒有並列。
輸入樣例:
6
3 65
2 80
1 100
2 70
3 40
3 0
輸出樣例:
2 150
#include <cstdio>
#include <cstring>
#include <cmath>
int score[100001] = { 0 };//學校連續編號,其編號不會超過10的5次方
int main()
{
int N = 0;
scanf("%d", &N);
for (int i = 0; i < N; i++)
{
int x = 0, t_score = 0;
scanf("%d %d", &x, &t_score);
score[x] += t_score;//注意此處爲累加
}
int max_x = 0, max_score = score[0];
for (int i = 1; i <= 100000; i++)//找出最大的輸出即可
{
if (score[i] > max_score)
{
max_x = i;
max_score = score[i];
}
}
printf("%d %d", max_x, max_score);
return 0;
}