1075. PAT Judge (25)

来源:互联网 发布:征管基础数据核实表 编辑:程序博客网 时间:2024/06/06 02:57

1075. PAT Judge (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

提交代码

解题思路:

题目意思很简单,就是给你一些人的成绩,然后你按照某些要求打印出来并且排序就可以了。第一步在结构体中定义一个成绩数组,结构体成员是可以是数组的。然后对成绩进行初始化,我们需要知道成绩是否需要更新。当输入的成绩大于0且大于原来的成绩时,则对成绩进行更新,同时对总分进行更新。当出现了分数大于-1则该人提交了课编译通过的代码,最终成绩需要打印出来,如果没有则不需要打印。注意:只要输入的成绩中有一个是大于-1的,则该人其他提交了但没有通过的分数是0,输出的时候需要输出0,没有提交才是-,这点需要特别注意。输出的时候判断是否提交了课通过编译的代码。

#include<iostream>#include<cstring>#include<algorithm>using namespace std;struct node{int cnt; //存储完全做出了多少题 int rank;//排名 int flag;//判断是否需要对其进行排名和输出 int sum;//总成绩 int id;//账号 int grade[10];//成绩数组 }a[10005];bool cmp(node x,node y){if(x.sum == y.sum){//先按总成绩 排名 if(x.cnt == y.cnt){//总成绩相同按完全做对的题目数排名 return x.id < y.id;//前两者相同按账号从小到大排名 }else{return x.cnt > y.cnt;}}else{return x.sum > y.sum;}}//初始化 void init(int n){for(int i = 0;i <= n;i++){a[i].cnt = 0;a[i].flag = 0;a[i].sum = 0;for(int j = 0;j <= 10;j++){a[i].grade[j] = -5;}}}int main(){int n,k,m;int source[10005];int d,b,c;//freopen("input.txt","r",stdin);scanf("%d%d%d",&n,&k,&m);init(n);for(int i = 1;i <= k;i++){scanf("%d",&source[i]);}while(m--){scanf("%d%d%d",&d,&b,&c);a[d].id = d;//判断是否提交过能通过编译的答案 if(c>-1){a[d].flag = 1;}//最新分数是否高于原来分数 if(c > a[d].grade[b]){//原来分数是否大于0 if(a[d].grade[b]>0){a[d].sum -= a[d].grade[b];}//提交了但没有通过编译为0分 if(c == -1){a[d].grade[b] = 0;}else{a[d].sum += c;a[d].grade[b] = c;}//完全做对题目数加1 if(c == source[b]){a[d].cnt++;}}}sort(a+1,a+n+1,cmp);a[1].rank =1; for(int i = 2;i <= n;i++){if(a[i].sum == a[i-1].sum){a[i].rank = a[i-1].rank;}else{a[i].rank = i;}}for(int i = 1;i<=n;i ++){if(a[i].flag == 0){//continue;}printf("%d %05d %d",a[i].rank,a[i].id,a[i].sum);for(int j = 1;j <= k;j++){if(a[i].grade[j]>-1){printf(" %d",a[i].grade[j]);}else{printf(" -");}}printf("\n");}return 0;}