跳到正文

个人记录

P9734

Wumq85约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年2月11日
收录
2026年3月15日
更新
2026年10月10日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
using namespace std;
struct stu{
	int math,science,english,pe;
}a[100010];
bool cmp(stu x,stu y){
	if(x.english+x.pe+x.math+x.science!=y.english+y.pe+y.math+y.science){
			return x.english+x.pe+x.math+x.science>y.english+y.pe+y.math+y.science;
	}
	else if(x.math!=y.math){
		return x.math>y.math;
	}
	else if(x.science!=y.science){
		return x.science>y.science;
	}
	else if(x.english!=y.english){
		return x.english>y.english;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].math>>a[i].english>>a[i].science>>a[i].pe;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		cout<<a[i].math<<" "<<a[i].english<<" "<<a[i].science<<" "<<a[i].pe<<endl;
	}
	return 0;
}
原文