信息学奥赛-奖学金(struct结构体)
#include<iostream>
using namespace std;
struct student{
int xuehao;
int chinese,math,english;
int total;
}a[300];
int main()
{
int n;
student temp;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i].chinese>>a[i].math>>a[i].english;
a[i].total=a[i].chinese+a[i].math+a[i].english;
a[i].xuehao=i+1;
}
for(int j=0;j<n-1;j++)
for(int i=0;i<n-j-1;i++)
{
if(a[i].total<a[i+1].total)
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
if(a[i].total==a[i+1].total && a[i].chinese<a[i+1].chinese)
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
for(int i=0;i<5;i++)
cout<<a[i].xuehao<<" "<<a[i].total<<endl;
return 0;
来源:CSDN
作者:Bubles_tang
链接:https://blog.csdn.net/qq_45897987/article/details/104040783