- 奖学金
- 2018-01-31 11:29:47 @
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,s,z,y;
struct
{
int num;
char name[10];
int chinese;
int math;
int english;
int sum;
}a[100],t;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i].num>>a[i].name>>a[i].chinese>>a[i].math>>a[i].english;
a[i].sum=a[i].chinese+a[i].math+a[i].english;
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i].sum<a[j].sum)
{
t=a[i];
a[i]=a[j];
a[j]=t;
s++;
}
else if(a[i].sum==a[j].sum&&a[i].chinese>a[j].chinese)
{
t=a[i];
a[i]=a[j];
a[j]=t;
s++;
}
else if(a[i].sum==a[j].sum&&a[i].chinese<a[j].chinese)
{
t=a[i];
a[i]=a[j];
a[j]=t;
s++;
}
}
if(s==5)
break;
}
{
for(i=1;i<=n;i++)
cout<<a[i].num<<" "<<a[i].sum<<endl;
}
return 0;
}
1 条评论
-
哈哈哈! LV 5 @ 2018-01-31 11:39:43
吧输出时的n改成5,题目只选出5个
- 1