PAT 乙级 1032 挖掘机技术哪家强

题目:

为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。

输入格式:

输入在第 1 行给出不超过 105​​ 的正整数 N,即参赛人数。随后 N 行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从 1 开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。

输出格式:

在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。

思路:将序号看做数组下标,根据下标保存学校的成绩,计算好后找出最大值

#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
struct Judge
{
	int score;
}judge[100000];
int main()
{
	int N = 0,index = 0, s,maxscore=-1;
	cin >> N; 
	for (int i = 0; i <=N; i++)
	{
		judge[i].score = 0;//初始化
	}
	for (int i = 0; i < N; i++)
	{
		cin >> index >> s;//输入对应序号和成绩
		judge[index ].score = judge[index ].score + s;//将序号看做地址下标,每个序号的成绩自加
	}
	for (int i = 1; i <=N; i++)
	{
		//找出成绩最高者
		if (maxscore < judge[i].score)
		{
			maxscore = judge[i].score;
			index = i;
		}
	}
	cout << index << " " << maxscore;
	return 0;
}
原文地址:https://www.cnblogs.com/zongji/p/12499956.html