超时求助
查看原帖
超时求助
980732
Main_Void_楼主2024/3/22 22:48
#include <iostream>
#include<algorithm>
using namespace std ;


struct Student {
	int Num ;
	int All;
	int Chinese ;
	int Math ;
	int English;
} a[110] ;
bool cmp(Student a , Student b)
{
	if( a.All > b.All)
	return true ;
	else if( a.All < b.All)
	return false ;
	else
	{
		if( a.Chinese > b.Chinese)
		return true ;
		else if( a.Chinese < b.Chinese)
		return false ;
		else
		{
			if(a.Num < b.Num)
			return true ;
			else
			return false ;
		}
	}
}
int main() {
    cin.tie(0) ;
   ios:: sync_with_stdio(false);
	int n ;
	cin >> n ;
	for ( int i = 1 ; i <= n ; i++) {
		a[i].Num = i ;
		cin >> a[i].Chinese >> a[i].Math >> a[i].English ;
		a[i].All = a[i].Chinese + a[i].English + a[i].Math ;
	}
	
	sort(a+1 , a+n + 1 , cmp) ;
	for( int i = 1; i  <= 5 ; i++)
	{
		cout << a[i].Num<<  " " << a[i].All <<endl ;
	}
}

最后两个点超时求助

2024/3/22 22:48
加载中...