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. pat1049. Counting Ones (30)

    1049. Counting Ones (30) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task ...

  2. SpringMVC03 ParameterMethodNameResolver(参数方法名称解析器) And XmlViewResolver(视图解析器)

    参数方法名称解析器 1.配置依赖包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht ...

  3. NopI 导出数据

    protected void exportAward(DataSet dsResult) { if (dsResult != null) { string fileName = System.Web. ...

  4. HDU 1114 Piggy-Bank 猪仔储钱罐(完全背包)

    题意: 给定一个存钱罐中要存硬币,知道空罐的重量和欲装满的重量,是否能装入?若能,打印最小价值.(注:能装的硬币重量一定刚刚好,里面的总价值要达到最小) 输入: 包含了T个测试例子,在第一行给出.接下 ...

  5. IOS UIButton常用属性

    //1.添加按钮 UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom]; //nameView.backgroundColor ...

  6. 【51nod1677】treecnt(树上数学题)

    点此看题面 大致题意: 给你一个节点从1~n编号的树,让你从中选择k个节点并通过选择的边联通,且要使选择的边数最少,让你计算对于所有选择k个节点的情况最小选择边数的总和. 题解 这道题乍一看很麻烦:最 ...

  7. vuejs组件的重要选项

    new Vue({ el:'#demo', data:{ message:'Hello vue.js!' } }) 我们看到这个括号里面包含了很多中间的选项,小括号里面其实是一些参数,这些参数指定了实 ...

  8. python_71_json序列化1

    #序列化:序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程. #本例把字典数据类型存成字符串存在硬盘 #文件只能存字符串和二进制码,字典之类的不可以 info={ ...

  9. C# checked运算符

    一.C# checked运算符 checked运算符用于对整型算术运算和显式转换启用溢出检查. 默认情况下,表达式产生的值如果超出了目标类型的范围,将会产生两种情况: ?常数表达式将导致编译时错误. ...

  10. 防止sql注入方法 如何防止java中将MySQL的数据库验证密码加上 ' or '1'= '1 就可以出现万能密码 的PreparedStatement

    package com.swift; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepar ...