题目1324:The Best Rank

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct grade{
    char stuID[7];
    int  cScore;
    int  mScore;
    int  eScore;
    double  aScore;
    int rank;
    int temprank;
    char course;
};

grade g[2000];

bool cmpBycSore(grade a,grade b){
     return a.cScore > b.cScore;
}
bool cmpBymSore(grade a,grade b){
    return a.mScore > b.mScore;
}
bool cmpByeSore(grade a,grade b){
    return a.eScore > b.eScore;
}
bool cmpByaSore(grade a,grade b){
    return a.aScore > b.aScore;
}

int main(){
    int m,n;
    while(cin >> n >> m){
        for(int i = 0 ; i < n ; i++){
            cin >> g[i].stuID >> g[i].cScore >> g[i].mScore >> g[i].eScore;
            g[i].aScore =  (g[i].cScore + g[i].mScore + g[i].eScore)/3;
            }
        
        sort(g,g + n,cmpByaSore);
        g[0].rank = 1;
        g[0].course = 'A';
        for(int i = 1 ; i < n ; i++){
            if(g[i].aScore == g[i-1].aScore)
                g[i].rank = g[i-1].rank;
            else
                g[i].rank = i + 1;
            g[i].course = 'A';
        }

        sort(g,g + n,cmpBycSore);
        g[0].temprank = 1;
        for(int i = 1 ; i < n ; i++){
            if(g[i].cScore == g[i-1].cScore)
                g[i].temprank = g[i-1].temprank;
            else
                g[i].temprank = i + 1;
        }
        for(int i = 0 ; i < n ; i++){
            if(g[i].temprank < g[i].rank){
                g[i].rank = g[i].temprank;
                g[i].course = 'C';
            }
        }
    
        sort(g,g + n,cmpBymSore);
        g[0].temprank = 1;
        for(int i = 1 ; i < n ; i++){
            if(g[i].mScore == g[i-1].mScore)
                g[i].temprank = g[i-1].temprank;
            else
                g[i].temprank = i + 1;
        }
        for(int i = 0 ; i < n ; i++){
            if(g[i].temprank < g[i].rank){
                g[i].rank = g[i].temprank;
                g[i].course = 'M';
            }
        }

        sort(g,g + n,cmpByeSore);
        g[0].temprank = 1;
        for(int i = 1 ; i < n ; i++){
            if(g[i].eScore == g[i-1].eScore)
                g[i].temprank = g[i-1].temprank;
            else
                g[i].temprank = i + 1;
        }
        for(int i = 0 ; i < n ; i++){
            if(g[i].temprank < g[i].rank){
                g[i].rank = g[i].temprank;
                g[i].course = 'E';
            }
        }
        char query[7];
        int i,j;
        for(i = 0;i < m;i++){
            cin >> query;
            for(j = 0;j < n;j++)
                if(!strcmp(query,g[j].stuID))
                    break;
            if(j < n)        
                 cout << g[j].rank << " " << g[j].course << endl;
            else
                 cout << "N/A" << endl;        
        }    
    }
    return 1;
}


你可能感兴趣的:(题目1324:The Best Rank)