PAT查找题---1032 挖掘机技术哪家强 (20分)

1032 挖掘机技术哪家强 (20分)

  • 从 1 开始连续编号
#include<iostream>
#include<algorithm>

const int maxn =100005;

using namespace std;


struct Node{
	int id,grade=0;
}stu[maxn];

bool cmp(Node a,Node b){
	return a.grade>b.grade;
}

int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		int id,grade;cin>>id>>grade;
		stu[id].id=id;
		stu[id].grade+=grade;
	}
	
	sort(stu+1,stu+n+1,cmp);
	cout<<stu[1].id<<" "<<stu[1].grade;
	return 0;
}
原文地址:https://www.cnblogs.com/bingers/p/13063905.html