再遇PAT天坑之1075. PAT Judge (25)

这是一篇关于PAT编程竞赛中1075题目的解析,主要讨论了如何从提交状态列表生成排名榜。题目要求不考虑分数超过满分的情况,未通过的题目分数记为0,从未通过任何题目的用户不显示,排名按总分降序、正确题目数降序、用户ID升序排列。文章涵盖了输入输出规格以及解题思路。
摘要由CSDN通过智能技术生成

25分的模拟题能这么繁琐也是醉了。。。
1.不用判断分数是否会超过FullMark
2.如果学生A被输出,他曾提交过某题x,但是没通过即输入“A x -1”,x成绩输出为0
3.与上相对,如果学生A所有题都没通过过,但是曾经提交过-1,不被输出
4.按照总分递减、答对递减、ID递增的顺序排列,仅列出有成绩的学生(0 - - -也算,但是- - - -不算)
The ranklist of PAT is generated from the status list, which shows the scores of the submittions. 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 contains 3 positive integers, N (<=104), the total number of users, K (<=5), the total number of problems, and M (<=105), the total number of submittions. It is then assumed that the user id’s are 5-digit numbers from 00001 to N, and the problem id’s are from 1 to K. The next line contains K positive integers p[i] (i=1, …, K), where p[i] corresponds to the full mark of the i-th problem. Then M lines follow, each gives the information of a submittion in the following format:

user_id problem_id partial_score_obtained

where partial_score_obtained is either -1 if the submittion cannot even pass the compiler, or is an integer in the range [0, p[problem_id]]. All the numbers in a line are separated by a space.

Output Specification:

For each test case, you are supposed to output the ranklist in the following format:

rank user_id total_score s[1] … s[K]

where rank is calculated according to the total_score, and all the users with the same total_score obtain the same rank; and s[i] is the partial score obtained for the i-th problem. If a user has never submitted a solution for a problem, then “-” must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted.

The ranklist must be printed in non-decreasing order of the ranks. For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems. And if there is still a tie, then they must be printed in increasing order of their id’s. For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist. It is guaranteed that at least one user can be shown on the ranklist.
上我迷之有几个点没过的代码

// ConsoleApplication2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <stdlib.h>
#include <stack>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <time.h>
#include <queue>
#include <functional>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include<iomanip>
using namespace std;
struct member
{
    int scores[5];
    int sumscore;
    int index;
    int perpect;
    bool isput;
    member()
    {
        sumscore = index = perpect = 0;
        scores[0] = scores[1] = scores[2] = scores[3] = scores[4] = -1;
        isput = false;
    }
};
bool compar(member m1, member m2)
{
    if (m1.sumscore != m2.sumscore) return m1.sumscore > m2.sumscore;
    else  {
        if (m1.perpect != m2.perpect) return m1.perpect > m2.perpect;
        else return m1.index < m2.index;
    }
}
member users[100000];
int scores[5];
int main()
{
    int n, k, m;
    cin >> n >> k >> m;
    for (int i = 0; i < k; i++) cin >> scores[i];
    int user, problem, score;
    for (int i = 0; i < m; i++)
    {
    //  scanf("%d%d%d", &user, &problem, &score);
        cin >> user >> problem >> score;
        users[user].index = user;
        if (users[user].scores[problem - 1] <score || users[user].scores[problem - 1]==-1)
        {
            if (score <=0)
            {
                users[user].scores[problem - 1] = 0;
                if (score == 0) users[user].isput = true;
                continue;
            }
            users[user].isput = true;
            if (score == scores[problem - 1])users[user].perpect++;
            if (users[user].scores[problem - 1] >0)
            {
                users[user].sumscore -= users[user].scores[problem - 1];
            }
            users[user].sumscore += score;
            users[user].scores[problem-1] = score;
        }
    }
    sort(users+1, users + n+1,compar);
    int rank=1;
    printf("%d %05d %d ",rank, users[1].index, users[1].sumscore);
    for (int j = 0; j < k; j++)
    {
        if (users[1].scores[j]>-1)
        {
            if (j < k - 1) printf("%d ", users[1].scores[j]);
            else printf("%d\n", users[1].scores[j]);
        }
        else
        {
            if (j < k - 1) printf("- ");
            else printf("-\n");
        }
    }
    int last=1;
    for (int i = 1; i <= n; i++) if (users[i].isput && users[i].sumscore != 0) last++;
    for (int i = 2; i <= n; i++)
    {
        if (users[i].isput)
        {
            if (users[i].sumscore != users[i - 1].sumscore)
            {
                if (users[i].sumscore != 0) rank = i;
                else rank = last;
                printf("%d %05d %d ", rank, users[i].index, users[i].sumscore);
                for (int j = 0; j < k; j++)
                {
                    if (users[i].scores[j]>-1)
                    {
                        if (j < k - 1) printf("%d ", users[i].scores[j]);
                        else printf("%d\n", users[i].scores[j]);
                    }
                    else
                    {
                        if (j < k - 1) printf("- ");
                        else printf("-\n");
                    }
                }
            }
            else
            {
                printf("%d %05d %d ", rank, users[i].index, users[i].sumscore);
                for (int j = 0; j < k; j++)
                {
                    if (users[i].scores[j]>-1)
                    {
                        if (j < k - 1) printf("%d ", users[i].scores[j]);
                        else printf("%d\n", users[i].scores[j]);
                    }
                    else
                    {
                        if (j < k - 1) printf("- ");
                        else printf("-\n");
                    }
                }
            }
        }
        else rank = last;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值