PAT A 1075. PAT Judge (25)

来源:互联网 发布:手机数据误删怎么恢复 编辑:程序博客网 时间:2024/05/22 03:34

题目

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 sametotal_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 2020 25 25 3000002 2 1200007 4 1700005 1 1900007 2 2500005 1 2000002 2 200005 1 1500001 1 1800004 3 2500002 2 2500005 3 2200006 4 -100001 2 1800002 1 2000004 1 1500002 4 1800001 3 400001 4 200005 2 -100004 2 0

Sample Output:

1 00002 63 20 25 - 182 00005 42 20 0 22 -2 00007 42 - 25 - 172 00001 42 18 18 4 25 00004 40 15 0 25 -

 

即根据提交情况,统计各个学生的分数,然后排序输出。

注意:

1、输入“-1”代表没有通过编译,该次的得分对应为0;而输出“-”则代表没有提交该题

2、需要在排名中剔除的是:没有提交,没有提交能通过编译“-1”的;而得0分的需要统计

3、通过一题指得到相应题的满分

4、rank只考虑总分

 

代码:

#include <iostream>#include <cstdio>#include <vector>#include <algorithm>using namespace std;struct stu//学生结构{int id;//idint s[5];//各题分数,内部从0开始编号int score;//总分int pass;//完全正确题目数int ns;//无提交或无任何通过编译标志,0代表没有通过stu()//初始化{id=0;score=0;pass=0;ns=0;for(int i=0;i<5;i++)s[i]=-2;//由于输出要求,对没有处理过的用-2表示}};bool cm(const stu &s1,const stu &s2);//比较int main(){int n,k,m;cin>>n>>k>>m;stu *student=new stu [n];//学生,标号i对应真实id-1int p[5];//分门分数int i,j;for(i=0;i<k;i++)//输入信息scanf("%d",&p[i]);int id,p_id,ps;for(i=0;i<m;i++){scanf("%d %d %d",&id,&p_id,&ps);if(ps>student[id-1].s[p_id-1])student[id-1].s[p_id-1]=ps;}for(i=0;i<n;i++)//计算总分,完全正确题目数,是否需要剔除{student[i].id=i+1;for(j=0;j<k;j++){if(student[i].s[j]>=0){student[i].score+=student[i].s[j];student[i].ns=1;}if(student[i].s[j]==p[j])student[i].pass++;}}stable_sort(student,student+n,cm); //稳定排序,可以免去一次id比较int rank=1;//当前的名次,处理并列用int score=student[0].score;//当前的分数for(i=0;i<n;i++){if(student[i].ns==0)//到达无用数据段跳出break;if(student[i].score!=score)//不是并列,刷新分数{rank=i+1;score=student[i].score;}printf("%d %05d %d",rank,student[i].id,student[i].score);//输出信息for(j=0;j<k;j++){if(student[i].s[j]>=0)printf(" %d",student[i].s[j]);else if(student[i].s[j]==-1)printf(" 0");elseprintf(" -");}printf("\n");}delete [] student;return 0;}bool cm(const stu &s1,const stu &s2)//按总分和完全正确题目数排序用比较{if(s1.score>s2.score)return true;else if(s1.score==s2.score)return s1.pass>s2.pass;elsereturn false;}


 

 

 

 

 

 

0 0
原创粉丝点击