用LUA(和C++)刷PAT (Advanced Level) ——1075 PAT Judge

该程序实现了一个学生评分系统,读取学生分数、提交情况及满分标准,然后根据成绩、满分解决方案数量和提交的有效性对学生进行排序。排序依据为成绩、满分解决方案数和ID。最后输出排名、学生ID、成绩以及每个问题的得分或未提交标记。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;

struct student{
    int id, grade = 0, perfect_solution = 0;
    bool valid = false;
    bool questions[5];//记录是否提交过
};

bool comp(student a, student b){
    if(a.grade != b.grade)
        return a.grade > b.grade;
    if(a.perfect_solution != b.perfect_solution)
        return a.perfect_solution > b.perfect_solution;
    if(a.valid != b.valid)
        return a.valid;
    return a.id < b.id;
}

int main()
{
    int N, K, M;
    cin>>N>>K>>M;
    int scores[5];
    int submittion[10000][5];
    memset(submittion, -2, sizeof(int)*50000);
    vector<student> students(N);
    
    for(int i = 0; i < K; i++)
        cin>>scores[i];
    
    for(int i = 0; i < M; i++){
        int st, question, score;
        scanf("%d %d %d", &st, &question, &score);
        st--;
        question--;
        submittion[st][question] = max(submittion[st][question], score);
        students[st].questions[question] = true;
    }
    
    for(int i = 0; i < N; i++){
        students[i].id = i;
        for (int j = 0; j < K; j++){
            if(students[i].questions[j] && submittion[i][j] >= 0)
            {
                students[i].grade += submittion[i][j];
                students[i].valid = true;
            }
            if(students[i].questions[j] && submittion[i][j] == scores[j])
                students[i].perfect_solution ++;
        }
    }
    sort(students.begin(), students.end(), comp);
    int current_grade = 0, current_rank = 0, real_rank = 0; 
    for(auto itr = students.begin(); itr != students.end(); itr++)
    {
        if (!itr -> valid)
            return 0;
        real_rank ++;
        if(itr -> grade != current_grade){
            current_grade = itr -> grade;
            current_rank = real_rank;
        }
        printf("%d %05d %d", current_rank, itr->id + 1, itr->grade);
        for(int i = 0; i < K; i++){
            if (itr-> questions[i])
                printf(" %d", max(submittion[itr->id][i], 0));
            else
                printf(" -");
        }
        printf("\n");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值