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 contains 3 positive integers, N (≤10​4​​), the total number of users, K (≤5), the total number of problems, and M (≤10​5​​), the total number of submissions. 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 submission in the following format:

user_id problem_id partial_score_obtained

where partial_score_obtained is either −1 if the submission 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.

Sample Input:

7 4 20
20 25 25 30
00002 2 12
00007 4 17
00005 1 19
00007 2 25
00005 1 20
00002 2 2
00005 1 15
00001 1 18
00004 3 25
00002 2 25
00005 3 22
00006 4 -1
00001 2 18
00002 1 20
00004 1 15
00002 4 18
00001 3 4
00001 4 2
00005 2 -1
00004 2 0

Sample Output:

1 00002 63 20 25 - 18
2 00005 42 20 0 22 -
2 00007 42 - 25 - 17
2 00001 42 18 18 4 2
5 00004 40 15 0 25 -

 #include <stdio.h>
#include <algorithm>
#include <set>
//#include <string.h>
#include <vector>
//#include <math.h>
#include <queue>
#include <iostream>
#include <string>
using namespace std;
const int maxn = ;
const int inf = ;
int n,k,m;
int p[];
struct peo{
int id=;
int pro_c=;
int score[]={-,-,-,-,-,-};
int flag=;
int total=;
}stu[maxn];
bool cmp(peo p1,peo p2){
//return p1.total==p2.total?(p1.pro_c==p2.pro_c?p1.id<p2.id:p1.pro_c>p2.pro_c):p1.total>p2.total;
if(p1.total!=p2.total) return p1.total>p2.total;
else if(p1.pro_c!=p2.pro_c){
return p1.pro_c>p2.pro_c;
}
else return p1.id<p2.id;
}
void po(int r,int i){
printf("%d %05d %d",r,stu[i].id,stu[i].total);
for(int j=;j<=k;j++){
if(stu[i].score[j]==-){
printf(" -");
}
else{
printf(" %d",stu[i].score[j]);
}
}
printf("\n");
} int main(){
scanf("%d %d %d",&n,&k,&m);
for(int i=;i<=k;i++){
scanf("%d",&p[i]);
}
for(int i=;i<m;i++){
int id,pro,score;
scanf("%d %d %d",&id,&pro,&score);
//stu[id].id = id;
//if(score>=0)
if(stu[id].score[pro]==-)stu[id].score[pro]=;
if(score>=stu[id].score[pro]){
stu[id].flag=;
stu[id].score[pro] = score;
}
}
for(int i=;i<=n;i++){
stu[i].id=i;
for(int j=;j<=k;j++){
if(stu[i].score[j]==p[j]) stu[i].pro_c++;
if(stu[i].score[j]!=-)stu[i].total+=stu[i].score[j];
}
}
sort(stu+,stu+n+,cmp);
int rank=;
po(rank,);
for(int i=;i<=n;i++){
if(stu[i].flag==)break;
if(stu[i].total==stu[i-].total){
po(rank,i);
}
else{
rank=i;
po(rank,i);
}
} }

注意点:常规复杂排序题,一开始输出时上限n忘记取,一直错误还找不到原因。还有一个错误就是结构体的初始化真的很重要,会有id不出现,这时没初始化结构体就会出现不可预知的错误,而你看代码的逻辑都还是对的,就会找不到bug。

PAT A1075 PAT Judge (25 分)——结构体初始化,排序的更多相关文章

  1. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  2. 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 PA ...

  3. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

    1075 PAT Judge (25分)   The ranklist of PAT is generated from the status list, which shows the scores ...

  4. PTA PAT排名汇总(25 分)

    PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...

  5. Linux C中结构体初始化

          在阅读GNU/Linux内核代码时,我们会遇到一种特殊的结构初始化方式.该方式是某些C教材(如谭二版.K&R二版)中没有介绍过的.这种方式称为指定初始化(designated in ...

  6. Linux下C结构体初始化

    1.前言 今天在公司看一同事写的代码,代码中用到了struct,初始化一个struct用的是乱序格式,如下代码所示: typedef struct _data_t { int a; int b; }d ...

  7. struct--------构造函数对结构体初始化的影响

    struct--------构造函数对结构体初始化的影响. 没有构造函数时使用如下: struct ClassBook{  int number;  int age; }; int main() { ...

  8. Linux C 结构体初始化三种形式

    最近看linux代码时发现了结构体 struct 一种新的初始化方式,各方查找对比后总结如下: 1. 顺序初始化教科书上讲C语言结构体初始化是按照顺序方式来讲的,没有涉及到乱序的方式.顺序初始化str ...

  9. Linux下C结构体初始化[总结]

    1.前言 今天在公司看一同事写的代码,代码中用到了struct,初始化一个struct用的是乱序格式,如下代码所示: typedef struct _data_t { int a; int b; }d ...

  10. C语言结构体初始化方法

    早上苏凯童鞋问我这个问题来着,写在这里. 我了解到的C中结构体初始化的方法大概有三种. 如这里我定义了一个结构体: typedef struct node { int x, y; }Node; 第一种 ...

随机推荐

  1. 在C语言结构体中添加成员函数

    我们在使用C语言的结构体时,经常都是只定义几个成员变量,而学过面向对象的人应该知道,我们定义类时,不只是定义了成员变量,还定义了成员方法,而类的结构和结构体非常的相似,所以,为什么不想想如何在C语言结 ...

  2. jsp使用servlet实现用户登录 及动态验证码

    在进行表单设计中,验证码的增加恰恰可以实现是否为“人为”操作,增加验证码可以防止网站数据库信息的冗杂等... 现在,我将讲述通过servlet实现验证码: 验证码作为一个图片,在页面中为“画”出来的, ...

  3. 安装Vue和创建一个Vue脚手架项目

    首先 安装node.js,安装成功可以在控制台输入[node --version ]查看node的版本,因为安装了node会自带npm所以我们可以用 [npm --version]查到npm版本  如 ...

  4. 3038 3n+1问题

    3038 3n+1问题  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 3n+1问题是一个简单有趣而又没有 ...

  5. mysql学习目录

    MySQL数据库 mysql 之库, 表的简易操作 mysql之行(记录)的详细操作 mysql之单表查询 mysql之多表查询 Navicat安装及简单使用 mysql之Navicat工具.pymy ...

  6. 怎样制作爽心的 dashboard ?

    在目前的大数据趋势中,数据的大屏可视化成为大家所推崇的一种互动展示模式.如果我们能够早一些了解和掌握这方面的技术,相信对我们的未来将会非常有帮助! 我们知道,通过报表工具实现大屏展示可以通过单张报表. ...

  7. Android滑动菜单使用(MenuDrawer和SlidingMenu)

    项目地址: https://github.com/gokhanakkurt/android-menudrawer   https://github.com/jfeinstein10/SlidingMe ...

  8. 精通initramfs构建step by step

    (一)hello world  一.initramfs是什么  在2.6版本的linux内核中,都包含一个压缩过的cpio格式 的打包文件.当内核启动时,会从这个打包文件中导出文件到内核的rootfs ...

  9. Python之SGDRegressor

    实现: # -*- coding: UTF-8 -*- import numpy as npfrom sklearn.linear_model import SGDRegressor __author ...

  10. 【第二篇】SAP ABAP7.5x新语法之OPEN SQL

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:SAP ABAP7.5x系列之OPEN SQL ...