PTA 5-15 PAT Judge (25分)

/*
 * 1.主要就用了个sort对结构体的三级排序
*/

#include "iostream"
#include "algorithm"
using namespace std;
int perfectScore[6];
struct Node {
    int id;
    int score[6] = {-2,-2,-2,-2,-2,-2}; /* 记录每一题的分数 初始化为-2代表没答题 */
    int totalScore = 0; /* 记录总分 */
    int perfectSolvedNum = 0; /* 记录得满分的题目总数 */
    bool flag = false; /* 判断该用户能否上ranklist 默认不能 */
}stu[10001];
int comp(const Node &stu1, const Node &stu2) {
    if (stu1.totalScore == stu2.totalScore) {
        if (stu1.perfectSolvedNum == stu2.perfectSolvedNum)
            return stu1.id < stu2.id;
        else
            return stu1.perfectSolvedNum > stu2.perfectSolvedNum;
    }
    else
        return stu1.totalScore > stu2.totalScore;
}
void getMSG(Node stu[10001],int n,int k) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            if(stu[i].score[j]>=0)
            stu[i].totalScore += stu[i].score[j];
            if (stu[i].score[j] >= 0)
                stu[i].flag = true;
            if (stu[i].score[j] == -1)
                stu[i].score[j] = 0;
            if (stu[i].score[j] == perfectScore[j])
                stu[i].perfectSolvedNum += 1;
        }
    }
}
int main() {
    int n, m, k;
    cin >> n >> k >> m;
    for (int i = 1; i <= k; i++)
        cin >> perfectScore[i];
    while (m--) {
        int stuId, proId, score;
        cin >> stuId >> proId >> score;
        stu[stuId].id = stuId;
        if (score > stu[stuId].score[proId])
            stu[stuId].score[proId] = score;
    }
    getMSG(stu, n, k);
    sort(stu+1,stu+n+1,comp);
    int l = 0;
    int temp = stu[1].totalScore;
    int rank = 1;
    for (int i = 1; i <= n; i++) {
        if (stu[i].flag) {
            if (stu[i].totalScore == temp)
                l++;
            else {
                rank += l;
                l = 1;
                temp = stu[i].totalScore;
            }
                cout << rank << " ";
            printf("%05d ", stu[i].id);
            cout << stu[i].totalScore;
            for (int j = 1; j <= k; j++) {
                if (stu[i].score[j] == -2)
                    cout << " -";
                else
                    cout << " " << stu[i].score[j];
            }
            cout << endl;
        }
    }
    return 0;
}
时间: 2024-10-29 19:07:57

PTA 5-15 PAT Judge (25分)的相关文章

PTA 10-排序5 PAT Judge (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge   (25分) The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Spe

PATA1075 PAT Judge (25 分)

The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Specification: Each input file contains one test case. For each case, the first line

【PAT甲级】1075 PAT Judge (25 分)

题意: 输入三个正整数N,K,M(N<=10000,K<=5,M<=100000),接着输入一行K个正整数表示该题满分,接着输入M行数据,每行包括学生的ID(五位整数1~N),题号和该题得分(-1表示没通过编译).输出排名,学生ID,总分和每一题的得分,第一优先为总分降序,第二优先为题目AC数降序,第三优先为学生ID升序(提交但未通过编译得分为0,未提交得分为-,不输出没有提交或者提交全都未通过编译的学生信息). trick: 测试点4为有学生先交了得到分的程序后该题后来又交了未通过编译

PTA乙级 (*1095 解码PAT准考证 (25分))

1095 解码PAT准考证 (25分) https://pintia.cn/problem-sets/994805260223102976/problems/1071786104348536832 题目大意:给出一组学生的准考证号和成绩,准考证号包含了等级(乙甲顶),考场号,日期,和个人编号信息,并有三种查询方式查询一:给出考试等级,找出该等级的考生,按照成绩降序,准考证升序排序查询二:给出考场号,统计该考场的考生数量和总得分查询三:给出考试日期,查询改日期下所有考场的考试人数,按照人数降序,考

PAT 1075. PAT Judge (25)

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定要熟练,还有就是编译没有通过为零分,没有提交显示为"-": #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int NUM=10001

1025 PAT Ranking (25 分)

1025 PAT Ranking (25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately

PAT Advanced 1093 Count PAT&#39;s (25分)

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters. Now given any string, you are supposed to tell the numb

1025 PAT Ranking (25分)

1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; struct stu{ int location_number; char

PTA 09-排序1 排序 (25分)

题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/720 5-12 排序   (25分) 给定NN个(长整型范围内的)整数,要求输出从小到大排序后的结果. 本题旨在测试各种不同的排序算法在各种数据情况下的表现.各组测试数据特点如下: 数据1:只有1个元素: 数据2:11个不相同的整数,测试基本正确性: 数据3:103个随机整数: 数据4:104个随机整数: 数据5:105个随机整数: 数据6:105个顺序整数: 数据7:105个逆序整数