调试了两天,结果晚上晩回寝还被老师骂了。但是终于还是把代码给调出来了。希望能帮到各位。
1 #include<bits/stdc++.h> 2 #include<string> 3 #include<iostream> 4 using namespace std; 5 struct student 6 { 7 int num; 8 int chinese; 9 int math; 10 int english; 11 int all; 12 }a[1202],m,c,x; 13 int n,b[5222]; 14 int main() 15 { 16 cin>>n; 17 for(int i=1;i<=n;i++) 18 { 19 cin>>a[i].chinese; 20 cin>>a[i].math; 21 cin>>a[i].english; 22 a[i].num=i; 23 a[i].all=a[i].chinese+a[i].math+a[i].english; 24 } 25 for(int j=1;j<=n-1;j++) 26 { 27 for(int k=j+1;k<=n;k++) 28 { 29 if(a[j].all<a[k].all) 30 { 31 m=a[j]; 32 a[j]=a[k]; 33 a[k]=m; 34 } 35 else if(a[j].all==a[k].all) 36 { 37 if(a[j].chinese<a[k].chinese) 38 { 39 c=a[j]; 40 a[j]=a[k]; 41 a[k]=c; 42 } 43 else if (a[j].chinese==a[k].chinese) 44 { 45 if(a[j].num>a[k].num) 46 { 47 x=a[j]; 48 a[j]=a[k]; 49 a[k]=x; 50 } 51 } 52 53 } 54 55 } 56 57 } 58 for(int u=1;u<=5;u++) 59 cout<<a[u].num<<" "<<a[u].all<<"\n"; 60 return 0; 61 }