PAT A1075 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 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 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 分)——结构体初始化,排序的更多相关文章
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- 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 ...
- PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)
1075 PAT Judge (25分) The ranklist of PAT is generated from the status list, which shows the scores ...
- PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
- Linux C中结构体初始化
在阅读GNU/Linux内核代码时,我们会遇到一种特殊的结构初始化方式.该方式是某些C教材(如谭二版.K&R二版)中没有介绍过的.这种方式称为指定初始化(designated in ...
- Linux下C结构体初始化
1.前言 今天在公司看一同事写的代码,代码中用到了struct,初始化一个struct用的是乱序格式,如下代码所示: typedef struct _data_t { int a; int b; }d ...
- struct--------构造函数对结构体初始化的影响
struct--------构造函数对结构体初始化的影响. 没有构造函数时使用如下: struct ClassBook{ int number; int age; }; int main() { ...
- Linux C 结构体初始化三种形式
最近看linux代码时发现了结构体 struct 一种新的初始化方式,各方查找对比后总结如下: 1. 顺序初始化教科书上讲C语言结构体初始化是按照顺序方式来讲的,没有涉及到乱序的方式.顺序初始化str ...
- Linux下C结构体初始化[总结]
1.前言 今天在公司看一同事写的代码,代码中用到了struct,初始化一个struct用的是乱序格式,如下代码所示: typedef struct _data_t { int a; int b; }d ...
- C语言结构体初始化方法
早上苏凯童鞋问我这个问题来着,写在这里. 我了解到的C中结构体初始化的方法大概有三种. 如这里我定义了一个结构体: typedef struct node { int x, y; }Node; 第一种 ...
随机推荐
- 了解java虚拟机—在TALB上分配对象(10)
由于对象一般会分配在堆上,而堆是全局共享的.因此在同一时间,可能有多个线程在堆上申请空间.每次对象分内都必须要进行同步,因此TLAB这种线程专属的区域来避免多线程冲突.TLAB本身占用了eden区的空 ...
- 百度地图坐标偏移,微信小程序地图偏移问题,腾讯地图坐标偏移
解决方案: 如果用百度的地图获取的坐标点,在微信小程序内使用,就会出现偏移 算法(lat和lng是经纬度,球面坐标): To_B是转到百度,To_G是转到GCJ-02(谷歌,高德,腾讯) var TO ...
- CSS之Medial Queries的另一用法:实现IE hack的方法
所谓Medial Queries就是媒体查询. 随着Responsive设计的流行,Medial Queries可算是越来越让人观注了.他可以让Web前端工程实现不同设备下的样式选择,让站点在不同的设 ...
- html/css学习笔记(一)
============================================================================================= 盒子模型 1 ...
- 【转】ASP.NET Core 依赖注入
DI在.NET Core里面被提到了一个非常重要的位置, 这篇文章主要再给大家普及一下关于依赖注入的概念,身边有工作六七年的同事还个东西搞不清楚.另外再介绍一下.NET Core的DI实现以及对实例 ...
- SoapUI SoapUI测试WebService协议接口简介
SoapUI测试WebService协议接口简介 by:授客 QQ:1033553122 1. 创建项目,入口:File -> New SOAP Project,或者右键默认项目Project- ...
- 数组中的逆序对(Java实现)
来源:剑指offer 逆序对定义:a[i]>a[j],其中i<j 思路:利用归并排序的思想,先求前面一半数组的逆序数,再求后面一半数组的逆序数,然后求前面一半数组比后面一半数组中大的数的个 ...
- [20171214]hashcat破解oracle口令.txt
[20171214]hashcat破解oracle口令.txt hashcat is the world's fastest and most advanced password recovery u ...
- Sql 查询结果 根据某个字段值 变更另外一个字段值 case when
SELECT CASE THEN '*******' ELSE Plate END AS Plate, CarType FROM Cars;
- ubuntu 配置拼音输入法步骤
今天配置了一下 ubuntu 拼音,要求使用ubuntu 内置拼音.大致步骤我记录一下: 配置拼音,使用 ibus pinyin,网上有很多帖子大致步骤: 1)安装 中文语言 2)安装ibus 3) ...