社区讨论
报错……
B3968[GESP202403 五级] 成绩排序参与者 1已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @m4cs2trn
- 此快照首次捕获于
- 2024/12/06 21:24 去年
- 此快照最后确认于
- 2024/12/06 21:46 去年
CPP
#include<bits/stdc++.h>
using namespace std;
struct xxx{
int c,m,e,z,z2,g,pm,ci;
//c是语文,m是数学,e是英语,z是总分,z2是c+m,g是语文数学最高分,pm是排名,ci是第几个输入的
bool is=false;
}a[10086];
int n;
bool cmp1(xxx x,xxx &y)
{
if(x.z>y.z)return true;
else if((x.z==y.z)&&(x.z2>y.z2))return true;
else if(((x.z==y.z)&&(x.z2==y.z2))&&x.g>y.g)return true;
else if(x.z==y.z&&x.z2==y.z2&&x.g==y.g)
{
y.is=true;
return true;
}
else return false;
}
bool cmp2(xxx x,xxx y)
{
return x.ci<y.ci;
}
int main()
{
//第一步:输入
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].z=a[i].c+a[i].m+a[i].e;
a[i].z2=a[i].c+a[i].m;
a[i].g=max(a[i].c,a[i].m);
a[i].ci=i;
}
//第二部:排序
stable_sort(a+1,a+1+n,cmp1);
//第三步:赋排名
for(int i=1;i<=n;i++)
{
if(a[i].is==false)
{
a[i].pm=i;
}
else
{
a[i].pm=a[i-1].pm;
}
}
//第四步:排序
stable_sort(a+1,a+1+n,cmp2);
//第五步:按需输出排名
for(int i=1;i<=n;i++)
{
cout<<a[i].pm<<endl;
}
return 0;
}
虽然但是,把引用传递去了就ok了,但这样
y.is就无法改变数值回复
共 2 条回复,欢迎继续交流。
正在加载回复...