PAT Advanced Level Practise 1012坑点

测试点2通不过,虽然只是占2/25的分,但是没AC很不爽,后来发现代码没有对分数相同的排名相同处理,题目没说,但感觉自己编程时应该要想到,还好只用2分。

不处理和处理对下面这个测试数据的结果不一样:

5 5
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 80 80 82
310105 82 82 83
310101
310102
310103
310104
310105

不处理

1 A
1 M
1 E
4 C
3 C

处理

1 A
1 M
1 E
4 C
2 C
/*
AC
2018/2/8
*/
#include 
#include 
#include 
using namespace std;

struct stu{
    long id;
    int c,m,e,a;
    int rank[4];
};

int cmpC(stu a,stu b){
    return a.c>b.c;
}

int cmpM(stu a,stu b){
    return a.m>b.m;
}

int cmpE(stu a,stu b){
    return a.e>b.e;
}

int cmpA(stu a,stu b){
    return a.a>b.a;
}

int main(){
    //freopen("1012input.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    stu stuary[n];
    for(int i=0;iscanf("%ld %d %d %d",&stuary[i].id,&stuary[i].c,&stuary[i].m,&stuary[i].e);
        stuary[i].a=(stuary[i].c+stuary[i].m+stuary[i].e)/3;
    }
    sort(stuary,stuary+n,cmpC);
    stuary[0].rank[1]=1;
    for(int i=1;i1]=i+1;
        if(stuary[i-1].c==stuary[i].c){
            stuary[i].rank[1]=stuary[i-1].rank[1];
        }
    }
    sort(stuary,stuary+n,cmpM);
    stuary[0].rank[2]=1;
    for(int i=1;i2]=i+1;
        if(stuary[i-1].m==stuary[i].m){
            stuary[i].rank[2]=stuary[i-1].rank[2];
        }
    }
    sort(stuary,stuary+n,cmpE);
    stuary[0].rank[3]=1;
    for(int i=1;i3]=i+1;
        if(stuary[i-1].e==stuary[i].e){
            stuary[i].rank[3]=stuary[i-1].rank[3];
        }
    }
    sort(stuary,stuary+n,cmpA);
    stuary[0].rank[0]=1;
    for(int i=0;i0]=i+1;
        if(stuary[i-1].a==stuary[i].a){
            stuary[i].rank[0]=stuary[i-1].rank[0];
        }
    }
    long ID;
    bool isExit;
    int index;
    int minRank,minRankIndex;
    while(m--){
        scanf("%ld",&ID);
        isExit=false;
        for(int i=0;iif(stuary[i].id==ID){
                isExit=true;
                index=i;
                break;
            }
        }
        if(!isExit){
            printf("N/A\n");
            continue;
        }

        minRank=20000;
        for(int i=0;i<4;i++){
            if(stuary[index].rank[i]printf("%d ",minRank);
        switch(minRankIndex){
            case 0:
            printf("A\n");
            break;
            case 1:
            printf("C\n");
            break;
            case 2:
            printf("M\n");
            break;
            case 3:
            printf("E\n");
            break;
        }
    }
    return 0;
}

你可能感兴趣的:(数据结构,PAT,C++)