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. 为什么我们使用Nginx而不是Apache?

    我们大多数的客户在他们的服务器上使用Apache作为Web服务器,尤其是部署在一个基于PHP系统的前端并且使用mod-PHP.鉴于扩张性和性能方面的原因,我们通常会建议他们改用Nginx和FPM. A ...

  2. mysql数据库忘记密码时如何修改(二)

    第一步:找到mysql数据库的my.ini配置文件,在[mysqld]下面添加一行代码:skip-grant-tables 第二步:运行services.msc进入服务管理界面,重启mysql服务. ...

  3. ElasticSearch多个字段分词查询高亮显示

    ElasticSearch关键字查询,将关键字分词后查询,多个字段,查询出来字段高亮显示. 查询方法如下: public List<NewsInfo> searcher2(String k ...

  4. mysql数据库的数据变更事件获取以及相关数据

    https://medium.com/@Masutangu/udf-trigger%E5%AE%9E%E6%97%B6%E7%9B%91%E6%8E%A7mysql%E6%95%B0%E6%8D%AE ...

  5. 《Head First 设计模式》之适配器模式与外观模式

    适配器模式(Adapter) 适配器(adapter-pattern):将一个类的接口,转换成客户期望的另一个接口.适配器让原来接口不兼容的类可以合作无间.两种形式: 对象适配器(组合) 类适配器(多 ...

  6. 《Head First 设计模式》之装饰者模式——饮料加工

    装饰者模式(Decorator) ——动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更有弹性的替代方案. 特点:建立拥有共同超类的装饰者与被装饰者来实现功能的动态扩展 原则:对扩展开放,对 ...

  7. WPF创建SignalR服务端(转)

    在网上看到了一个帖子,比较详细,博主写的很好. 地址:http://blog.csdn.net/lordwish/article/details/51786200

  8. pyinstaller打包python源程序访问hive

    1.需求 使用hvie server一段时间后,业务部门需要自己不定时的查询业务数据,之前这一块都是他们提需求我们来做,后来发现这样重复一样的工作放在我们这边做是在没有效率,遂提出给他们工具或者web ...

  9. 根据图片的URL来实例化图片

    正常的Image图片类实例化的时候都需要使用本地的虚拟路径而不能使用URL,如果使用URL就会出现   不支持 URI 格式  这样的问题,正确的写法如下: HttpWebRequest reques ...

  10. 【BZOJ1257】[CQOI2007] 余数之和(数学题)

    点此看题面 大致题意: 求\(\sum_{i=1}^nk\%i\). 关于除法分块 这是一道除法分块的简单应用题. 式子转换 显然\(k\%i\)是一个很难处理的项. 于是我们就要使用使用一个常用的套 ...