1075 PAT Judge (25 分)

所有的坑都试了一遍,还是没找到哪错了,唉…

//
// Created by 22385 on 2022/1/24.
//
/*
    最后一个测试点未通过:
        一个人提交的所有分数都是0,也应该要输出,而此时按照总分排序,没有提交过的可能排在前
        先按输出标志排序
        还是没通过!!!!!
    学生的id需要初始化吗?...
 */
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

const int maxn=5;

struct record{
    char id[10];
    int test_num;
    int test_score;
}records[100005];

struct student{
    char id[10];
    int total_score=0;
    int test_score[5]={-2,-2,-2,-2,-2};//-2表示未提交
    int AC=0;//AC的题目数量
    int flag=0;//标识考生是否有通过编译的提交
    int rank=0;//排名
}stu[1005];

//取每道题最好的成绩
bool cmp1(record a, record b){
    if(strcmp(a.id,b.id)!=0) return strcmp(a.id,b.id)<0;
    else if(a.test_num!=b.test_num) return a.test_num<b.test_num;
    else return a.test_score>b.test_score;
}
bool cmp2(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.AC!=b.AC) return a.AC>b.AC;
    else return strcmp(a.id,b.id)<0;
}

int main(){
    int n, total_test_num, sub_num;
    scanf("%d %d %d", &n, &total_test_num, &sub_num);

    int value[maxn];
    for(int i=0;i<total_test_num;i++){
        scanf("%d", &value[i]);
    }

    for(int i=0;i<sub_num;i++){
        scanf("%s %d %d",records[i].id,&records[i].test_num,&records[i].test_score);
    }
    sort(records,records + sub_num,cmp1);
    strcpy(stu[0].id,records[0].id);
    //同一道题目多次提交选最高
    int test_num;
    for(int i=0,j=0,k;i<sub_num;i++){
        if(strcmp(records[i].id,stu[j].id)!=0){//下一个考生
            strcpy(stu[++j].id,records[i].id);
        }
        test_num = records[i].test_num;
        if(stu[j].test_score[test_num-1]==-2){
            if(records[i].test_score!=-1){
                stu[j].flag=1;
                stu[j].test_score[test_num-1]=records[i].test_score;
                stu[j].total_score +=stu[j].test_score[test_num-1];
                if(stu[j].test_score[test_num-1]==value[test_num-1]) stu[j].AC++;
            }else{
                stu[j].test_score[test_num-1]=0;
            }
        }
    }
    sort(stu,stu+n,cmp2);
    int isHave = 1;
    for(int i=0;i<n;i++){
        if(stu[i].flag==0){
            if(i==0) isHave=0;
            break;
        }else{
            if(i!=0 && stu[i].total_score==stu[i-1].total_score){
                stu[i].rank=stu[i-1].rank;
            }else{
                stu[i].rank=i+1;
            }
            printf("%d %s %d",stu[i].rank,stu[i].id,stu[i].total_score);
            for(int j=0;j<total_test_num;j++){
                if(stu[i].test_score[j]==-2) printf(" -");
                else printf(" %d",stu[i].test_score[j]);
            }
            printf("\n");
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值