1. 程式人生 > >1032 挖掘機技術哪家強 (20 分)

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<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a[100007];
	scanf("%d",&n);
	memset(a,0,sizeof(a));
	int maxsch=0,maxnum=0;
	int sch,num;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&sch,&num);
		a[sch]=a[sch]+num; 
		if(maxnum<a[sch])
		{
			maxsch=sch;
			maxnum=a[sch];
		}
	}
	printf("%d %d",maxsch,maxnum);
	return 0;
}