PAT A1075. PAT Judge

#include <iostream>
#include <algorithm>
#include <cstring>
#define Max_K 6
using namespace std;
struct Student
{
    int id;//准考证号
    int score_of_problem[Max_K];//每道题的分数
    int num_solved;//AC的题目数
    bool flag;//是否有通过了编译的提交
    int total_score;//总分
}student[100010];

bool cmp(Student a,Student b)
{
    if(a.flag != b.flag) return a.flag>b.flag;//需要输出的学生排在前面
    else if(a.total_score!=b.total_score) return a.total_score>b.total_score;
    else if(a.num_solved!=b.num_solved) return a.num_solved>b.num_solved;
    else return a.id<b.id;
}
int N,K,M,perfectScore[Max_K];


void init()//初始化
{
    for(int j=1;j<=N;j++)
    {
        student[j].id = j;
        student[j].total_score = 0;
        student[j].num_solved=0;
        student[j].flag = false;
        memset(student[j].score_of_problem,-1,sizeof(student[j].score_of_problem));//每道题目的得分初始化为1
    }
}

int main()
{

    scanf("%d %d %d",&N,&K,&M);
    init();
    for(int i = 1;i<=K;i++)
    {
        scanf("%d",&perfectScore[i]);
    }
    int tmpId,tmpProblem,tmpScore;
    for(int i = 0;i<M;i++)
    {
        scanf("%d %d %d",&tmpId,&tmpProblem,&tmpScore);
        if(tmpScore!= -1){
            student[tmpId].flag = true;
        }
        if(tmpScore == -1 &&student[tmpId].score_of_problem[tmpProblem] == -1)
        {
            student[tmpId].score_of_problem[tmpProblem] = 0;
        }
        if(tmpScore==perfectScore[tmpProblem]&&student[tmpId].score_of_problem[tmpProblem]<perfectScore[tmpProblem])//某道题第一次获得满分,完美解题数加一
        {
            student[tmpId].num_solved++;
        }
        if(tmpScore>student[tmpId].score_of_problem[tmpProblem])//获得更高分数,修改对应的分数
        {
            student[tmpId].score_of_problem[tmpProblem] = tmpScore;
        }

    }


    for(int i = 1;i<=N;i++)
     for(int j = 1;j<=K;j++)
     {
         if(student[i].score_of_problem[j]!=-1)
            student[i].total_score += student[i].score_of_problem[j];
     }
    sort(student+1,student+N+1,cmp);

    int r = 1; //用于排名,当前为1;
    for(int i = 1;i<=N && student[i].flag==true;i++)
    {
        if(i>1 && student[i].total_score != student[i-1].total_score)
            r = i;//当考生分数低于前一个考生的分数,则其排名为在该考生前面的考生的总人数

        printf("%d %05d %d",r,student[i].id,student[i].total_score);
        for(int j = 1;j<=K;j++)
        {
            if(student[i].score_of_problem[j] == -1)
                printf(" -");
            else
                printf(" %d",student[i].score_of_problem[j]);
        }
        printf("\n");
    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值