#4WA sort求助
查看原帖
#4WA sort求助
444195
caramel_qwq楼主2022/3/8 19:37

求dalao帮调

#include<iostream>
#include<algorithm>
#define ll long long
#define MAXN 1008
using namespace std;
ll n,r=1;
struct student{
	ll id,sum,rank;
	ll sa,sb,sc,sd;
}a[MAXN];
bool cmp(student x,student y){
	return x.sum>y.sum;
}
int main(){
	cin>>n;
	if(n==1){
		cout<<1<<"\n";
		return 0;
	}
	for(ll i=1;i<=n;i++){
		cin>>a[i].sa>>a[i].sb>>a[i].sc>>a[i].sd;
		a[i].id=i;
		a[i].sum=a[i].sa+a[i].sb+a[i].sc+a[i].sd;
	}
	sort(a+1,a+n+1,cmp);
	for(ll i=1;i<=n;i++){
		if(i+1>n) continue;  
		if(a[i].sum!=a[i+1].sum){
			a[i].rank=r;
		}
		if(a[i].sum==a[i+1].sum){
			a[i].rank=r;
			a[i+1].rank=r;
			i++;
		}
		r++;
	}
	/*for(ll i=1;i<=n;i++){
		cout<<"id="<<a[i].id<<" sum="<<a[i].sum<<" rank="<<a[i].rank<<"\n";
	}*/
	for(ll i=1;i<=n;i++){
		if(a[i].id==1){
			cout<<a[i].rank<<"\n";
			break;
		}
	}
	return 0;
}
2022/3/8 19:37
加载中...