題目描述
爲了用事實說明挖掘機技術到底哪家強,PAT組織了一場挖掘機技能大賽。現請你根據比賽結果統計出技術最強的那個學校。
輸入格式:
輸入在第1行給出不超過105的正整數N,即參賽人數。隨後N行,每行給出一位參賽者的信息和成績,包括其所代表的學校的編號(從1開始連續編號)、及其比賽成績(百分制),中間以空格分隔。
輸出格式:
在一行中給出總得分最高的學校的編號、及其總分,中間以空格分隔。題目保證答案唯一,沒有並列。
輸入樣例:
6
3 65
2 80
1 100
2 70
3 40
3 0
輸出樣例:
2 150
C++代碼
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+5;
int peopel[maxn];
int main(){
int n;
while(cin>>n){
memset(peopel,-1,sizeof(peopel));
for(int i=0;i<n;i++){
int x,cord;cin>>x>>cord;
if(peopel[x]<0) peopel[x]=cord;
else peopel[x]+=cord;
}
int max=0;
for(int i=0;i<maxn;i++)
if(peopel[i]>=0&&peopel[i]>=peopel[max]) max=i;
cout<<max<<" "<<peopel[max]<<endl;
}
return 0;
}