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 分)的更多相关文章

  1. PAT A1075 PAT Judge (25 分)——结构体初始化,排序

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  2. A1075 PAT Judge (25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  3. 7-19 PAT Judge(25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  4. 10-排序5 PAT Judge (25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  5. A1075. PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submittions. Th ...

  6. PAT甲级——A1075 PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  7. PAT_A1075#PAT Judge

    Source: PAT A1075 PAT Judge (25 分) Description: The ranklist of PAT is generated from the status lis ...

  8. PAT 1075 PAT Judge[比较]

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

  9. 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 ...

随机推荐

  1. Java操作Excel之POI简单例子

    /** * 利用POI操作Excel表单 * * 需要jar包: * HSSF针对03及以前版本,即.xls后缀 * |---poi-3.16.jar * XSSF针对07及以后版本,即xlsx后缀 ...

  2. 利用Java程序将字符串进行排序与拼接

    1.初始生成字符串的代码程序: package com.map.test; import java.util.ArrayList; import java.util.Collections; impo ...

  3. 用mvc模式,整理前两次的代码并增加登陆注册

    简单的servlet连接mysql数据库 使用mvc的登录注册 commons-dbutils-1.6 mysql-connector-java-5.1.40-bin c3p0-0.9.5.2 mch ...

  4. jdbc操作数据库的步骤

    package com.jckb; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepare ...

  5. 1 误删dbf文件造成ORA-01109: 数据库未打开.

    1.cmd-sqlplus /nolog-conn system/pwd as sysdba 2.shutdown immediate; 3.startup mount; 4.alter databa ...

  6. Photoshop之切图

    基本(繁琐)操作: 切JPG图(即带背景的图): 1.         选切片工具(另外,切片选择工具能选择切片和删除切片),切 2.         存储为Web所用格式(快捷键Ctrl + Shi ...

  7. html5标签的兼容性处理

    HTML5的语义化标签以及属性 1.可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单 2.使用他们能让代码语义化更直观,而且更方便SEO ...

  8. 十分钟玩转 jQuery、实例大全(参考自博主索宁)

    十分钟玩转 jQuery.实例大全(参考自博主索宁) 一.简介 书写规则 支持链式操作: 在变量前加"$"符号(var $variable = jQuery 对象): 注:此规定并 ...

  9. SpringBoot集成mybatis和mybatis generator

    利用搭建的基本的spring boot框架,集成 mybatis + generator 1.设置 maven 的相关配置: File  - setting - maven 设置 Maven home ...

  10. /pentest/cisco/cisco-auditing-tool

    /pentest/cisco/cisco-auditing-tool ./CAT    -h host 扫描单个主机 -w  wordlist 猜测团体名称列表 -a passlist   猜测密码列 ...