___wa___ @ 2022-08-11 19:31:21
#include<bits/stdc++.h>
using namespace std;
struct xuesheng
{
string mingzi;
int yuwen,shuxue,yingyu;
int zongchengji;
int id;
}xuesheng[1001];
int main()
{
int a;
cin>>a;
for(int i=0;i<a;i++)
{
cin>>xuesheng[i].mingzi;
cin>>xuesheng[i].yuwen;
cin>>xuesheng[i].shuxue;
cin>>xuesheng[i].yingyu;
xuesheng[i].id=i;
}
for(int i=0;i<a;i++)
{
xuesheng[i].zongchengji=xuesheng[i].yuwen+xuesheng[i].shuxue+xuesheng[i].yingyu;
}
for(int i=0;i<a;i++)
{
for(int ii=0;ii<a;ii++)
{
if(xuesheng[i].zongchengji<xuesheng[ii].zongchengji&&xuesheng[i].id<xuesheng[ii].id)
{
swap(xuesheng[i].zongchengji,xuesheng[ii].zongchengji);
swap(xuesheng[i].mingzi,xuesheng[ii].mingzi);
swap(xuesheng[i].id,xuesheng[ii].id);
swap(xuesheng[i].yuwen,xuesheng[ii].yuwen);
swap(xuesheng[i].shuxue,xuesheng[ii].shuxue);
swap(xuesheng[i].yingyu,xuesheng[ii].yingyu);
}
else
if(xuesheng[i].zongchengji==xuesheng[ii].zongchengji)
if(xuesheng[i].id<xuesheng[ii].id)
{
swap(xuesheng[i].zongchengji,xuesheng[ii].zongchengji);
swap(xuesheng[i].mingzi,xuesheng[ii].mingzi);
swap(xuesheng[i].id,xuesheng[ii].id);
swap(xuesheng[i].yuwen,xuesheng[ii].yuwen);
swap(xuesheng[i].shuxue,xuesheng[ii].shuxue);
swap(xuesheng[i].yingyu,xuesheng[ii].yingyu);
}
}
}
cout<<xuesheng[0].mingzi<<" "<<xuesheng[0].yuwen<<" "<<xuesheng[0].shuxue<<" "<<xuesheng[0].yingyu;
return 0;
}
样例过了
求dalao帮助!
by GuangyuHuashi @ 2022-08-11 20:07:14
@wa
by ___wa___ @ 2022-08-12 18:00:26
@GuangyuHuashi else部分好像全错了诶(原来)
by GuangyuHuashi @ 2022-08-12 18:01:50
@wa 这个确实(吧),我也不是很确定,所以如您所见,我把它们全删了
by GuangyuHuashi @ 2022-08-12 18:03:12
而且这个也没有标号的必要,相等直接不交换就可以了
by ___wa___ @ 2022-08-12 18:04:13
@GuangyuHuashi 但是还是只AC了第一个点(我自己删的)
by GuangyuHuashi @ 2022-08-12 18:05:28
@wa 第一个if中不需要比较编号
by ___wa___ @ 2022-08-12 18:05:49
标号有必要啊,不标号样例都过不了
by GuangyuHuashi @ 2022-08-12 18:06:07
同时ii变量可以从i+1开始遍历
by GuangyuHuashi @ 2022-08-12 18:07:27
for(int i=0;i<a-1;i++)
{
for(int ii=i+1;ii<a;ii++)
{
if(xuesheng[i].zongchengji<xuesheng[ii].zongchengji)
{
swap(xuesheng[i].zongchengji,xuesheng[ii].zongchengji);
swap(xuesheng[i].mingzi,xuesheng[ii].mingzi);
swap(xuesheng[i].id,xuesheng[ii].id);
swap(xuesheng[i].yuwen,xuesheng[ii].yuwen);
swap(xuesheng[i].shuxue,xuesheng[ii].shuxue);
swap(xuesheng[i].yingyu,xuesheng[ii].yingyu);
}
}
}
这样写
by ___wa___ @ 2022-08-12 18:07:44
因为不标号的话,在循环的时候会换两次(一次i,一次ii)