90分,第八点错误,求助!!!同志们!!!
查看原帖
90分,第八点错误,求助!!!同志们!!!
772705
dangchuncn楼主2022/8/26 20:30
#include <bits/stdc++.h>
using namespace std;

struct Student{
	int num;
	int c,m,e;
	int score;
};

bool cmp(Student a,Student b){
	if(a.score>b.score) return 1;
	else if(a.score<b.score) return 0;
	else{
		if(a.c>b.c) return 1;
		else if(a.c<b.c) return 0;
		else{
			if(a.num>b.num) return 1;
			else return 0;
		}
	}
}
	
int main(){
	int n,cn,eg,ma;
	struct Student a[310];
	cin>>n;
	for(int i=1;i<=n;i++){
		a[i].num=i;
		cin>>a[i].c>>a[i].m>>a[i].e;
		a[i].score=a[i].c+a[i].m+a[i].e;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=5;i++){
		cout<<a[i].num<<" "<<a[i].score<<endl;
	}
}
2022/8/26 20:30
加载中...