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. 极飞P20农业无人机多机协同作业飞行

                      来自为知笔记(Wiz)

  2. webpack4流程笔记

    初始化 mkdir webpack-demo   ->新建文件夹  cd webpack-demo  ->进入文件夹 第一步 npm init -y  -> 初始化项目(生成pack ...

  3. UINavigationControlle 之 UINavigationBar及navigationItem关系探讨

    在设置标题栏时常常遇到修改标题.修改返回按钮标题.增加一些按钮等需求,实现过程中一般会把UINavigationController.UINavigationBar.navigationItem及se ...

  4. 工作流性能优化(敢问activiti有扩展性?)(1)

    工作流待办(首页待办列表),加载缓慢,activiti本机,看了代码又是全部数据加载到内存,然后代码过滤,我为什么又说又呢? 用VisualVM做性能测试:   之前同事给的解决方案: 1.把&quo ...

  5. JS事件阻止冒泡的写法

    $("body").on("click", "#id", function (ev) { ev = ev || event;要写的逻辑代码 ...

  6. POI 怎么设置Excel整列的CellStyle啊

    POI 怎么设置Excel整列的CellStyle啊,而不是循环每个Cell.因为现在是生成Excel模板,不知道客户会输入多少行. 问题补充: 指尖言 写道 好像没有这个方法,CellStyle是C ...

  7. codeforces 599D Spongebob and Squares

    很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...

  8. UVA - 1639 Candy (概率,精度)

    X表示剩下的糖数量,如果最后打开的是p对应的盒子.划分:Xi表示剩下i个糖,最后一次选的概率为p, 前面的服从二项分布.根据全概率公式和期望的线性性,求和就好了. 精度处理要小心,n很大,组合数会很大 ...

  9. POJ 1065 Wooden Sticks(LIS,最少链划分)

    题意:求二维偏序的最少链划分. 用到Dilworth定理:最少链划分=最长反链.(对偶也成立,个人认为区别只是一个维度上的两个方向,写了个简单的证明 相关概念:偏序集,链,反链等等概念可以参考这里:h ...

  10. 实现带查询功能的ComboBox控件

    实现效果: 知识运用: ComboBox控件的AutoCompleteMode属性 public AutoCompleteMode AutoCompleteMode{get;set;} //属性值为枚 ...