王寅泽 @ 2021-03-06 14:03:21
#include <bits/stdc++.h>
using namespace std;
struct
{
int number;
int chinese=0;
int math=0;
int english=0;
int all;
}student[300];
int main()
{
int pupil,temp;
for(int i=0;i<300;i++)
{
student[i].number=i+1;
cout << student[i].all << endl;
}
cin >> pupil;
for(int i=0;i<pupil;i++)
{
cin >> student[i].chinese >> student[i].math >> student[i].english;
student[i].all=student[i].chinese+student[i].math+student[i].english;
}
for(int a=0;a<pupil-1;a++)
{
for(int b=a+1;b<pupil;b++)
if(student[b].all<student[b+1].all)
{
temp=student[b].number;
temp=student[b].chinese;
temp=student[b].math;
temp=student[b].english;
temp=student[b].all;
student[b].number=student[b+1].number;
student[b].chinese=student[b+1].chinese;
student[b].math=student[b+1].math;
student[b].english=student[b+1].english;
student[b].all=student[b+1].all;
student[b+1].number=temp;
student[b+1].chinese=temp;
student[b+1].math=temp;
student[b+1].english=temp;
student[b+1].all=temp;
}
else
{
if(student[b].chinese<student[b+1].chinese)
{
temp=student[b].number;
temp=student[b].chinese;
temp=student[b].math;
temp=student[b].english;
temp=student[b].all;
student[b].number=student[b+1].number;
student[b].chinese=student[b+1].chinese;
student[b].math=student[b+1].math;
student[b].english=student[b+1].english;
student[b].all=student[b+1].all;
student[b+1].number=temp;
student[b+1].chinese=temp;
student[b+1].math=temp;
student[b+1].english=temp;
student[b+1].all=temp;
}
else
{
if(student[b].number<student[b+1].number)
{
temp=student[b].number;
temp=student[b].chinese;
temp=student[b].math;
temp=student[b].english;
temp=student[b].all;
student[b].number=student[b+1].number;
student[b].chinese=student[b+1].chinese;
student[b].math=student[b+1].math;
student[b].english=student[b+1].english;
student[b].all=student[b+1].all;
student[b+1].number=temp;
student[b+1].chinese=temp;
student[b+1].math=temp;
student[b+1].english=temp;
student[b+1].all=temp;
}
}
}
}
for(int i=0;i<5;i++)
{
cout << student[i].number << " " << student[i].all << endl ;
}
return 0;
}
by Interstice @ 2021-03-06 14:54:43
亲测sort只需要23行啊……你写这么多干啥