为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。
输入在第 1 行给出不超过 1 的正整数 N,即参赛人数。随后 N 行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从 1 开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。
在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。
6
3 65
2 80
1 100
2 70
3 40
3 0
2 150
1 #include <iostream> 2 using namespace std; 3 //此种算法简单粗暴,非常不优美,唯有考试的时候争分夺秒不得已用之,平时请换个优雅的算法 4 int main(){ 5 int sum=0; 6 int schoolSum[100005]; 7 long n; 8 cin>>n; 9 int school; 10 int schoolmax=0; 11 int score; 12 long j; 13 //初始化数组,否则数组中会有各种各样的值, 14 for(int i=0;i<100005;i++){ 15 schoolSum[i]=0; 16 } 17 for(int i=0;i<n;i++){ 18 sum=0; 19 cin>>school>>score; 20 sum = sum+score; 21 schoolSum[school]+=sum; 22 } 23 for(long i=0;i<100005;i++){ 24 if(schoolSum[i]>schoolmax){ 25 schoolmax=schoolSum[i]; 26 j=i; 27 } 28 } 29 //cout<<schoolSum[1]<<" "<< schoolSum[2]<<" "<< schoolSum[3]; 30 cout<<j<<" "<<schoolmax; 31 return 0; 32 }
原文:https://www.cnblogs.com/geyang/p/12312159.html