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. 《深入理解Java虚拟机:JVM高级特性与最佳实践》读书笔记

    第一部分 走进Java 一.走进Java 1.概述 java广泛应用于嵌入式系统.移动终端.企业服务器.大型机等各种场合,摆脱了硬件平台的束缚,实现了“一次编写,到处运行”的理想 2.java技术体系 ...

  2. Spring基于XML方式的使用

    一.IoC配置 IoC的配置是通过Spring的xml文件的bean标签进行的. 1.bean标签介绍 bean标签一般是在xml文件进行配置的,xml文件一般样式如下: <?xml versi ...

  3. Flutter 布局(六)- SizedOverflowBox、Transform、CustomSingleChildLayout详解

    本文主要介绍Flutter布局中的SizedOverflowBox.Transform.CustomSingleChildLayout三种控件,详细介绍了其布局行为以及使用场景,并对源码进行了分析. ...

  4. Kotlin入门(17)等式判断的情况

    话说等式可是编程语言最基本的表达式之一,不管哪种高级语言,无一例外都采用双等号“==”判断两个变量是否相等:就算是复杂的对象,在Java中也可通过equals函数判断两个实例是否相等.按理说这些能够满 ...

  5. Fragment 中 ListView绑定ContextMenu

    package com.example.administrator.imbobo.controller.fragment; import android.content.BroadcastReceiv ...

  6. JavaScript大杂烩14 - 使用JQuery(上)

    JQuery意义 - Why? 为什么要使用JQuery,从我个人来说,就是这么几点:简化代码 + 统一行为 + 功能强大 + 搭配方便. 简化代码是从写代码的角度来说的,实现同样的功能,如果用Jav ...

  7. javascript模块化编程-详解立即执行函数表达式IIFE

    一.IIFE解释 全拼Imdiately Invoked Function Expression,立即执行的函数表达式.  像如下的代码所示,就是一个匿名立即执行函数: (function(windo ...

  8. 洗礼灵魂,修炼python(31)--面向对象编程(1)—面向对象,对象,类的了解

    面向对象 1.什么是面向对象 (图片来自网络) 哈哈,当然不是图中的意思. 1).面向对象(Object Oriented,OO)是软件开发方法.利用各大搜索引擎得到的解释都太官方,完全看不懂啥意思对 ...

  9. Linux RCU 机制详解

    1.简介: RCU(Read-Copy Update)是数据同步的一种方式,在当前的Linux内核中发挥着重要的作用. RCU主要针对的数据对象是链表,目的是提高遍历读取数据的效率,为了达到目的使用R ...

  10. Ubuntu18.04 更换源

    在虚拟机新建一个Ubuntu18.04.1-live-server-amd64当做服务器 在安装软件时报错: slave@slave:~$ sudo -s[sudo] password for sla ...