- 奖学金
- 2018-01-31 12:52:29 @
#include<bits/stdc++.h>
using namespace std;
struct student{
int num;
int chinese;
int math;
int english;
int zong;
}student[300+10],t;
int main(){
int n,i,j;
cin>>n;
for(i=1;i<=n;i++){
student[i].num=i;
cin>>student[i].chinese>>student[i].math>>student[i].english;
student[i].zong=student[i].chinese+student[i].math+student[i].english;
}
for(i=1;i<=n-1;i++)
for(j=1;j<=n-i;j++){
if(student[j].zong<student[j+1].zong){
t=student[j];student[j]=student[j+1];student[j+1]=t;
}
if(student[j].zong==student[j+1].zong){
if(student[j].chinese<student[j+1].chinese){
t=student[j];student[j]=student[j+1];student[j+1]=t;
}
}
if(student[j].zong==student[j+1].zong){
if(student[j].chinese==student[j+1].chinese){
if(student[j].num<student[j+1].num)
t=student[j];student[j]=student[j+1];student[j+1]=t;
}
}
}
for(i=1;i<=5;i++)
cout<<student[i].num<<" "<<student[i].zong<<endl;
return 0;
}
3 条评论
-
垃圾,没有之一 (·) LV 7 @ 2018-02-03 16:01:06
#include<bits/stdc++.h>
using namespace std;
struct{
int num;
int c,m,e,s;
}a[310],t;
int main()
{
int n,i,j;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i].c>>a[i].e>>a[i].m;
a[i].s=a[i].c+a[i].e+a[i].m;
a[i].num=i;
}
for(i=1;i<=n-1;i++)
for(j=1;j<=n-i;j++)
if(a[j].s<a[j+1].s)
{
t=a[j];a[j]=a[j+1];a[j+1]=t;
}
else if(a[j].s==a[j+1].s)
{
if(a[j].c<a[j+1].c)
{
t=a[j];a[j]=a[j+1];a[j+1]=t;
}
}
for(i=1;i<=5;i++)
cout<<a[i].num<<" "<<a[i].s<<endl;
return 0;
} -
2018-02-03 15:59:15@
注释一下
-
2018-01-31 13:35:48@
同上
- 1