牛客网PAT-练兵场-挖掘机技术哪家强

题目地址:https://www.nowcoder.com/pat/6/problem/4058

题解:用数组下标当学校编号。输入一次数据的时候,直接在相应数组下标位置累加内容,同时更新最大的总分的学校

 1 /**
 2 * Copyright(c)
 3 * All rights reserved.
 4 * Author : YCute
 5 * Date : 2019-11-19-21.01.44
 6 * Description : 输入时处理数据
 7 */
 8 #include<iostream>
 9 #include<cstdio>
10 #include<cmath>
11 #include<cstring>
12 #include<algorithm>
13 using namespace std;
14 int main(){
15     int n;
16     int s[100005]={0};
17     scanf("%d",&n);
18     int id=0;
19     while(n--){
20         int a,b;
21         scanf("%d %d",&a,&b);
22         s[a]+=b;
23         id=s[id]>s[a]?id:a;
24     }
25     printf("%d %d\n",id,s[id]);
26     return 0;
27 }

猜你喜欢

转载自www.cnblogs.com/cutelife/p/11892438.html