PAT甲级 1075 PAT Judge

情况不少需要好好分析

#include 
#include 
#include 
#include 

using namespace std;
int n,k,m;
int per_rank[5];

typedef struct student
{
    int id;
    int score[5];
    int score_f[5];
    int total_score;
    int total_solve;
    int rank;
    int flag =0;

}stu;
stu s[10005];
bool cmp(stu a,stu b)
{
    if (a.total_score!=b.total_score)return a.total_score>b.total_score;
    else if(a.total_solve!=b.total_solve)return a.total_solve>b.total_solve;
    else return a.id<b.id;
    
    
}

int main()
{   
    scanf("%d %d %d",&n,&k,&m);
    for(int i =0;i<k;i++)
        scanf("%d",&per_rank[i]); 
    for(int i=0;i<n;i++)
        s[i].id = i+1;
    while(m--)
    {
        int temp_id, temp_p, temp_score;
        scanf("%d %d %d", &temp_id, &temp_p, &temp_score);
        temp_p--;
        temp_id--;
        
        if (s[temp_id].score[temp_p] < temp_score)
        {
            s[temp_id].score[temp_p] = temp_score;
        }
        if(s[temp_id].score_f[temp_p]!=2)
        {
            if(temp_score==per_rank[temp_p])s[temp_id].score_f[temp_p] = 2;
        else if(temp_score!=-1)s[temp_id].score_f[temp_p] = 1;
        else s[temp_id].score_f[temp_p] = 3;

        }
        
            
    }
    for(int i =0;i<n;i++)
        for(int j =0;j<k;j++)
        s[i].total_score+=s[i].score[j];
    for(int i =0;i<n;i++)
        for(int j =0;j<k;j++)
            if(s[i].score_f[j]==2)s[i].total_solve++;
    //for(int i =0;i
   // printf("%d %d %d\n",s[4].score[0],s[4].score_f[0],per_rank[0]);
    for(int i =0;i<n;i++)
    {
        
        for(int j =0;j<k;j++)
        {
            if(s[i].score_f[j]!=0&&s[i].score_f[j]!=3)
            {
                s[i].flag=1;
                break;
            }

        }
            

    }
        
    sort(s,s+n,cmp);
    s[0].rank = 1;


    int count = 2;
    for(int i =1;i<n;i++)
        if(s[i].total_score==s[i-1].total_score)s[i].rank = s[i-1].rank;
        else s[i].rank = i+1;
    
    for(int i =0;i<n;i++)
    {
        
        if(s[i].flag==1)
        {
            printf("%d %05d %d",s[i].rank,s[i].id,s[i].total_score);
            for(int j =0;j<k;j++)
            if(s[i].score_f[j]!=0)printf(" %d",s[i].score[j]);
            else printf(" -");
            printf("\n");
            

        }
        
    }
    
    return 0;
}

你可能感兴趣的:(PAT甲级)