P1093 [NOIP2007 普及组] 奖学金(模拟排序)

Description of the topic

A primary school recently received a grant to offer scholarships to top five students with outstanding academic performance. At the end of the term, each student has three subjects: Chinese, Maths, and English. First according to the total score from high to low sort, if the total score of two students is the same, and then according to the language score from high to low sort, if the total score of two students and language scores are the same, then the provisions of the small number of students in front, so that each student's ranking is the only certainty.

Task: The total score is calculated based on the results of the 3 courses entered, then sorted by the above rules, and finally output the top five students' school numbers and total scores in the ranking order. Note that in the top 5 students, each person's scholarship is different, so you must strictly follow the above rules. For example, in a correct answer, if the output data for the first two rows (two numbers per row: school number, total score) is:

77 279279
55 279279

The meaning of these two rows of data is: the two students with the highest total score are 77th and 55th in turn. The total scores of the two students were 279279 (the total score was equal to the sum of the three subjects of input, mathematics and English), but the students with the number 77 had higher scores in Chinese. If your top two output data is:

55 279279
77 279279

Error handling by output, no score can be scored.

Enter the format

A total of n1 lines.

The 11th behavior is a positive integer n (sle 300)n (≤300), indicating the number of students participating in the selection.

On lines 22 to n1n1, each row has 33 numbers separated by spaces, each between 00 and 100100. The 33 numbers in line jj indicate, in turn, the scores of students with the number j-1j-1 in Chinese, math, and English. Each student's number is numbered 1 to n1 n in the order in which they are entered (exactly the line number minus 11 of the input data).

The data given are correct and need not be tested.

Thanks to Huang Xiao U Drinks for correcting the input format

The output format

There are 5 rows, each of which is a positive integer separated by spaces, representing the number and total score of the first 55 students in turn.

A sample of the input and output

Enter #1 copy

6
90 67 80
87 66 91
78 89 91
88 99 77
67 89 64
78 89 98

Output #1 copy

6 265
4 264
3 258
2 244
1 237

Enter #2 copy

8
80 89 89
88 98 78
90 67 80
87 66 91
78 89 91
88 99 77
67 89 64
78 89 98

Output #2 copy

8 265
2 264
6 264
1 258
5 258

题意分析就是模拟排序判断;

#include<bits/stdc++.h>
const int maxn=1e6+7;
using namespace std;
struct node
{
	int sum;
	int x,y,z;
	int num;
}s[maxn];
bool cmp(node a,node b)
{
	if(a.sum>b.sum)return 1;
	else if(a.sum<b.sum)return 0;
	else
	{
		if(a.x>b.x)return 1;
		else if(a.x<b.x) return 0;
		else
		{
			if(a.num<b.num)return 1;
			else return 0; 
			
			
		}
	}
}
int main()
{
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		s[i].num=i;
		cin>>s[i].x>>s[i].y>>s[i].z;
		s[i].sum=s[i].x+s[i].y+s[i].z;
	}
	sort(s+1,s+1+t,cmp);
	for(int i=1;i<=5;i++)
	{
		cout<<s[i].num<<' '<<s[i].sum<<endl; 
	}

}

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法编程张老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值