A1075 PAT Judge (25)(25 分)
A1075 PAT Judge (25)(25 分)
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.
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 -
思考
自己能写出一个程序的能力是很重要的 ,从0开始的框架搭建,就是不仅每一步能给出代码实现 ,框架也是会搭建的。
这里排序的记录,有一个问题,就是如果以准考证号为下标,那么就会出现一些未定义的条目造成问题,排序不方便。
解决的办法可以是初始化。
将一直保持初始状态的条目,保证排序放在最后面(最前面也行),反正放在一个独立的整体区域。
c语言中要使用memset需要#include <memory.h>或者是<string.h>至少是dev c++编译需要这个才能通过
AC代码
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
//#include <memory.h>//使用memset函数必须使用这个,尽量赋值0或-1 ,string.h也可以
#define maxn 10005//段错误不是在这
//struct Sub{
// int id;//准考证号
// int problem;// 题号
// int subscore;//该题得分
//}Persub[maxn];//提交记录
struct Student{
int id;//准考证号
int score[6];// 每道题的得分
bool flag;//是否有能通过编译的提交
int score_all;//总分
int solve; //完美解题数
}stu[maxn];
int n,k,m;//n位考生
int full[6];//每道题的满分 ,,题号从1开始计数
int cmp(const void*a,const void*b){
// struct Student*aa=(Student*)a;
// struct Student*bb=(Student*)b;
struct Student*aa=a;
struct Student*bb=b;
if(aa->score_all != bb->score_all)
return aa->score_all < bb->score_all ? 1:-1;
else if(aa->solve != bb->solve)
return aa->solve < bb->solve ? 1:-1;
else return aa->id > bb->id ? 1:-1;
}
void init(){ //初始化
for(int i=1; i<=n; i++){
stu[i].id=i; //准考证号记为i
stu[i].score_all=0; //总分初始化为0
stu[i].solve=0; //完美解题数初始化为0
stu[i].flag=false; //初始化为没能通过编译的提交
memset(stu[i].score,-1,sizeof(stu[i].score)) ; //题目得分记为-1,这是编译未通过的代表
}
}
int main(){
scanf("%d %d %d",&n,&k,&m);//n为学生数,也是准考证号范围
init();
for(int i=1;i<=k;i++){
scanf("%d",&full[i]);//天啊,这边缺了一个取地址符,8月17日,这会导致PAT段错误
}
/*读取m条提交记录*/
/*排序规则*/
/*第一,K道题所得总分降序排列
第二,总分相同,按完美解决(即获得题目满分)的题目数量从高到低排序
第三,若完美解决的题目数量也相同,则按准考证从小到大排列*/
int u_id, p_id, score_obtained;
for(int i = 0; i < m; i++) {
scanf("%d%d%d", &u_id, &p_id, &score_obtained);
if(score_obtained != -1) {
stu[u_id].flag = true;//该考生有能通过编译的提交
}
if(score_obtained == -1 && stu[u_id].score[p_id] == -1) {
stu[u_id].score[p_id] = 0;//第一次遇到编译错误时,把分数赋值为0便于输出
}//注意这一句在更新分数较大值之前,第一次遇到编译错误,防止出现先有>0的分,然后又给记为0了
if(score_obtained == full[p_id] && stu[u_id].score[p_id] < full[p_id]) {
stu[u_id].solve++;//第一次出现满分,更新满分数,防止第二次满分,满分问题个数重复计数
}
if(score_obtained > stu[u_id].score[p_id]) {
stu[u_id].score[p_id] = score_obtained;
}
}
for(int i = 1; i <= n; i++) {// 计算总分
for(int j = 1; j <= k; j++) {
if(stu[i].score[j] != -1) {
stu[i].score_all += stu[i].score[j];
}
}
}
qsort(stu + 1, n, sizeof (struct Student) , cmp);//排序
int r = 1;//当前排名
for(int i = 1; i <= n && stu[i].flag == true; i++) {//在需要输出的考生里查询
if(i > 1 && stu[i].score_all != stu[i - 1].score_all) {
r = i;
}//这个PAT排名思维的实现简单,都不需要那个if语句了
printf("%d %05d %d", r, stu[i].id, stu[i].score_all);
for(int j = 1; j <= k; j++) {
if(stu[i].score[j] == -1) {
printf(" -");
} else {
printf(" %d", stu[i].score[j]);
}
}
printf("\n");
}
return 0;
}
A1075 PAT Judge (25)(25 分)的更多相关文章
- PAT A1075 PAT Judge (25 分)——结构体初始化,排序
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- A1075 PAT Judge (25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- 7-19 PAT Judge(25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- 10-排序5 PAT Judge (25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- A1075. PAT Judge
The ranklist of PAT is generated from the status list, which shows the scores of the submittions. Th ...
- PAT甲级——A1075 PAT Judge
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- PAT_A1075#PAT Judge
Source: PAT A1075 PAT Judge (25 分) Description: The ranklist of PAT is generated from the status lis ...
- PAT 1075 PAT Judge[比较]
1075 PAT Judge (25 分) The ranklist of PAT is generated from the status list, which shows the scores ...
- 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 ...
随机推荐
- C++中的引用和指针
引用和指针有何区别?何时只能使用指针而不能使用引用? 引用是一个别名,不能为 NULL 值,不能被重新分配:指针是一个存放地址的变量.当需要对变量重新赋以另外的地址或赋值为 NULL 时只能使用 ...
- .NET导出excel方法
//导出 private string outFileName = ""; private string fullFilename = ""; private ...
- 使用AlarmManager定期执行工作
新建一个Service来模拟后台执行的程序,PollingService.java: package com.ryantang.rtpollingdemo; import android.app.No ...
- 认识与入门 MarkDown (转Te_Lee)
Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...
- mockJs语法糖用例
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Vue.js(2.x)之计算属性
昨天看完大神的文章后,深感惭愧,硬着头皮继续看官网文档,然而这真的没是没办法,介绍的实在有些敷衍: 1).计算属性:也不说下computed是计算属性关键词,vm实例是可以像代理data一样代理com ...
- 使用纯css实现波浪效果
有时候我们需要实现水晃动的效果,其实我们可以通过css旋转动画和圆角来实现. 首先来2个div,外层div相对定位,内层div绝对定位,内层div大致位于外层div上半部分.外层div设置一个颜色较深 ...
- Android应用瘦身
转:https://zhuanlan.zhihu.com/p/25465537 瘦身的目的 从目的导向来看,我们是不会无缘无故去做一件事情的,那我们对应用瘦身的目的是为了什么?答案是:提高下载转化率. ...
- Android 常用RGB值及名称
Android 常用RGB值及名称 颜 色 RGB值 英文名 中文名 #FFB6C1 LightPink 浅粉红 #FFC0CB Pink 粉红 #DC143C Crimson 深红/猩红 #F ...
- JAVA时间加工类
/** * 当天凌晨 */ public static Calendar startOfDay(Calendar c) { if (c == null) { return c; } c.set(Cal ...