江湖救急!!!!!!!!

P1093 [NOIP2007 普及组] 奖学金

FYH666666 @ 2023-10-25 17:57:05

#include<stdio.h>
struct q{
    int y,s,g,z,m;
}q[305];
int main(){
    int s=0,u=0,l=0,n,b[10],v;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&q[i].y,&q[i].s,&q[i].g);
        q[i].m=i;
        q[i].z=q[i].y+q[i].s+q[i].g;
    }
    for(int i=1;i<=n;i++){
        if(q[i].z<=q[i+1].z){
            if(q[i].z<q[i+1].z){
                q[i].z=s;
                q[i].z=q[i+1].z;
                q[i+1].z=s;
                q[i].y=u;
                q[i].y=q[i+1].y;
                q[i+1].y=u;
                q[i].m=l;
                q[i].m=q[i+1].m;
                q[i+1].m=l;
            }
        }
        else if(q[i].z==q[i+1].z){
            if(q[i].y<q[i+1].y){
                q[i].z=s;
                q[i].z=q[i+1].z;
                q[i+1].z=s;
                q[i].y=u;
                q[i].y=q[i+1].y;
                q[i+1].y=u;
                q[i].m=l;
                q[i].m=q[i+1].m;
                q[i+1].m=l;
            }
            else if(q[i].m<q[i+1].m){
                q[i].z=s;
                q[i].z=q[i+1].z;
                q[i+1].z=s;
                q[i].y=u;
                q[i].y=q[i+1].y;
                q[i+1].y=u;
                q[i].m=l;
                q[i].m=q[i+1].m;
                q[i+1].m=l;
            }
        }
    }
    for(int k=1;k<=5;k++){
        printf("%d %d\n",q[k].m,q[k].z);
    }
    return 0;
} 

by xuchong123321 @ 2023-11-04 14:44:06

用swap不香吗?


by xuchong123321 @ 2023-11-04 14:45:01

还有排序再套一层循环


|