原题连接:https://pta.patest.cn/pta/test/16/exam/4/question/677

题目如下:

The ranklist of PAT is generated from the status list, which shows the scores of the submissions. 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, NNN (≤104\le 10^4≤10​4​​), the total number of users, KKK (≤5\le 5≤5), the total number of problems, and MMM (≤105\le 10^5≤10​5​​), the total number of submissions. It is then assumed that the user id's are 5-digit numbers from 00001 to NNN, and the problem id's are from 1 to KKK. The next line contains KKK positive integers p[i] (i=1, ..., KKK), where p[i] corresponds to the full mark of the i-th problem. Then MMM lines follow, each gives the information of a submission in the following format:

user_id problem_id partial_score_obtained

where partial_score_obtained is either −1-1−1 if the submission 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 -

__________________________________________________________________________________________________________________________
  这道题首先要对题意理解清楚,就是对输入的用户数据进行排序,分数高的先输出,如果分数相等,则比较完全正确的解答的数量,如果再相等,则按照序号升序输出;
另外输出的时候,要注意是编译未通过(即输入-1)和为提交任何题目的(需要做标记)不用输出。
  题目的核心在于排序,我是利用的c语言中的qsort.另外,对题目的逻辑分析和代码实现也是一个难点;最后,初始的用户序号要为最大,否则排序会有问题(在代码中
已经注释)导致最后一个测试会通不过。
  解答该题的时候也参考了其他博主的代码!
 #include<stdio.h>
#include<stdlib.h>
#define K 6
#define N 10001 typedef struct user{
int uuid;
int rank;
int total_score;
int p[K];
int perfectly_score;
int pass;
}User; User uu[N]; int cmp(const void *u1,const void *u2)
{
User *uu1=(User *)u1;
User *uu2=(User *)u2;
if (uu2->total_score>uu1->total_score)return ;
else if (uu2->total_score==uu1->total_score)
{
if (uu2->perfectly_score>uu1->perfectly_score)return ;
else if (uu2->perfectly_score==uu1->perfectly_score)return (uu1->uuid-uu2->uuid);
}
return -;
} int main()
{
int n,k,m,score[K]={};
int i,j,uuid,pro,sco;
scanf("%d %d %d",&n,&k,&m);
for (i=;i<=k;i++)scanf("%d",&score[i]);
/* 初始化 */
for (i=;i<n;i++)
{
uu[i].perfectly_score=;
uu[i].total_score=;
uu[i].pass=;
uu[i].uuid=N; //如果id不初始为最大,那么没有通过编译的会排在通过编译但得分为0的同学之前,
// 从而影响得分为0的同学的rank值
for (j=;j<=k;j++)
{
uu[i].p[j]=-;
}
}
/* 将每个用户解决的相应问题的相应最大得分进行纪录 */
for (i=;i<m;i++)
{
scanf("%d %d %d",&uuid ,&pro,&sco);
if (uu[uuid-].p[pro]<sco)uu[uuid-].p[pro]=sco;
}
/* 将数据进行整理 */
for (i=;i<n;i++)
{
int flag,total,perfect;
flag=total=perfect=;
for (j=;j<=k;j++)
{
if (uu[i].p[j]>=) //>=0 说明该用户有通过了编译的
{
flag=;
total+=uu[i].p[j];
if (uu[i].p[j]==score[j])perfect++;
}
}
if (flag)
{
uu[i].uuid=i+;
uu[i].perfectly_score=perfect;
uu[i].total_score=total;
uu[i].pass=;
}
} qsort(uu,n,sizeof(uu[]),cmp); uu[].rank=;
printf("%d %05d %d",uu[].rank,uu[].uuid,uu[].total_score);
for (j=;j<=k;j++)
{
if (uu[].p[j]>=)printf(" %d",uu[].p[j]);
else if (uu[].p[j]==-)printf(""); //单独处理-1,即没有通过编译得分为0
else printf(" -"); // 没有提交输出 -
}
printf("\n"); for (i=;i<n;i++)
{
if (uu[i].pass> ){
if (uu[i].total_score==uu[i-].total_score)uu[i].rank=uu[i-].rank;
else uu[i].rank=i+; // 注意是i+1
printf("%d %05d %d",uu[i].rank,uu[i].uuid,uu[i].total_score);
for (j=;j<=k;j++)
{
if (uu[i].p[j]>=)printf(" %d",uu[i].p[j]);
else if (uu[i].p[j]==-) printf("");
else printf(" -");
}
printf("\n");}
} return ;
}

  

PAT Judge的更多相关文章

  1. PAT 1075 PAT Judge[比较]

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

  2. A1075 PAT Judge (25)(25 分)

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

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

  4. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

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

  5. PAT_A1075#PAT Judge

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

  6. 10-排序5 PAT Judge

    用了冒泡和插入排序 果然没有什么本质区别..都是运行超时 用库函数sort也超时 The ranklist of PAT is generated from the status list, whic ...

  7. PAT 1075. PAT Judge (25)

    题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1075 此题主要考察细节的处理,和对于题目要求的正确理解,另外就是相同的总分相同的排名的处理一定 ...

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

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

  9. A1075. PAT Judge

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

随机推荐

  1. ubuntu 配置VPN

    1.  sudo apt-get install pptpd 2.  修改/etc/pptpd.conf , vi /etc/pptpd.conf 找到#localip 192.168.0.1和#re ...

  2. 【Django】--基础知识

    一 什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. Web应 ...

  3. MFC注册窗口类以及FindWindow按窗口类名查询

    很多玩游戏的人都知道一般游戏客户端程序是不允许双开的,就是说在同一游戏在启动的时候,是无法打开多个窗口.很多其他软件如酷狗播放器等也是这样.如果把打开的窗口最小化,这时重新启动程序,最小化的窗口会被显 ...

  4. [Tool]Inno Setup创建软件安装程序。

    这篇博客将介绍如何使用Inno Setup创建一个软件安装程序. Inno Setup官网:http://www.jrsoftware.org/isinfo.php. 可以下载到最新的Inno Set ...

  5. 社区活动分享PPT:使用微软开源技术开发微服务

    上周六在成都中生代技术社区线下活动进行了一个名为"微软爱开源-使用微软开源技术开发微服务"的技术分享. 也算是给很多不熟悉微软开源技术的朋友普及一下微软最近几年在开源方面所做的努力 ...

  6. maven权威指南学习笔记(四)—— maven生命周期(lifecycle)

    定义: 生命周期是包含在一个项目构建中的一系列有序的阶段 举个例子来说就是maven 对一个工程进行: 验证(validate) -- 编译源码(compile) -- 编译测试源码(test-com ...

  7. 【web maven】新建的项目 controller也有,从前台跳转后台 无法找到对应的controller

    碰上很 愣的问题: 使用maven搭建项目完成,项目页面写好,实体.Dao.Service.Controller都有了,但是指定Controller中的某个方法中一直不能从前台进入后台 原因: 没有w ...

  8. 数据结构0103汉诺塔&八皇后

    主要是从汉诺塔及八皇后问题体会递归算法. 汉诺塔: #include <stdio.h> void move(int n, char x,char y, char z){ if(1==n) ...

  9. 360浏览器导出Excel闪退BUG

    最近这半个月在疯狂的修改各种BUG,所以比较少更新博客. 现在谈谈这个360浏览器导出Excel的BUG的解决方法. 该BUG常出现在win7系统与xp系统导出Excel的瞬间关闭导出弹窗. 目前互联 ...

  10. 使用SHFB(Sandcastle Help File Builder)建立MSDN风格的代码文档

    使用SHFB(Sandcastle Help File Builder)建立MSDN风格的代码文档 下载地址:http://sandcastle.codeplex.com/ 下载地址2:http:// ...