PAT 甲级 1075 PAT Judge (25 分) 铭记

本是古典 何须时尚 2024-02-19 21:33 164阅读 0赞

1075 PAT Judge (25 分)

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, N (≤104), the total number of users, K (≤5), the total number of problems, and M (≤105), the total number of submissions. 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 submission in the following format:

  1. user_id problem_id partial_score_obtained

where partial_score_obtained is either −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:

  1. 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:

  1. 7 4 20
  2. 20 25 25 30
  3. 00002 2 12
  4. 00007 4 17
  5. 00005 1 19
  6. 00007 2 25
  7. 00005 1 20
  8. 00002 2 2
  9. 00005 1 15
  10. 00001 1 18
  11. 00004 3 25
  12. 00002 2 25
  13. 00005 3 22
  14. 00006 4 -1
  15. 00001 2 18
  16. 00002 1 20
  17. 00004 1 15
  18. 00002 4 18
  19. 00001 3 4
  20. 00001 4 2
  21. 00005 2 -1
  22. 00004 2 0

Sample Output:

  1. 1 00002 63 20 25 - 18
  2. 2 00005 42 20 0 22 -
  3. 2 00007 42 - 25 - 17
  4. 2 00001 42 18 18 4 2
  5. 5 00004 40 15 0 25 -

1.如果提交了,但是都是0,那应该输出。

2.如果是-1,但总成绩不为0,-1改为0输出。

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<cstring>
  5. using namespace std;
  6. int grade[6];
  7. struct node{
  8. int id;
  9. int g[6];
  10. int n_m; //统计有几门是满分
  11. int rank;
  12. int sum;
  13. int f; //是否得过分
  14. };
  15. node a[10005];
  16. void init(int n){
  17. for(int i=1;i<=n;i++)
  18. {
  19. fill(a[i].g,a[i].g+6,-1);
  20. a[i].n_m=0; // 统计满分
  21. a[i].rank=0;
  22. a[i].sum=0;
  23. a[i].f=0; // 是否有通过编译的提交
  24. a[i].id=0;
  25. }
  26. }
  27. int cmp(node a,node b)
  28. {
  29. if(a.sum!=b.sum)
  30. return a.sum>b.sum;
  31. else
  32. {
  33. if(a.n_m!=b.n_m)
  34. return a.n_m>b.n_m;
  35. else
  36. return a.id<b.id;
  37. }
  38. }
  39. int main()
  40. {
  41. int n,k,m,i,j,t_id,t,tn;
  42. scanf("%d %d %d",&n,&k,&m);
  43. init(n);
  44. for(i=1;i<=k;i++)
  45. scanf("%d",&grade[i]);
  46. for(i=0;i<m;i++)
  47. {
  48. scanf("%d %d %d",&t_id,&t,&tn);
  49. a[t_id].id=t_id;
  50. if(tn!=-1) // 如果有,则标记
  51. a[t_id].f=1;
  52. if(tn==-1&&a[t_id].g[t]==-1) // 如果第一次 ,则 改为0 便于输出
  53. a[t_id].g[t]=0;
  54. if(tn==grade[t]&&tn>a[t_id].g[t])
  55. a[t_id].n_m++;
  56. if(tn>a[t_id].g[t])
  57. a[t_id].g[t]=tn;
  58. }
  59. for(i=1;i<=n;i++)
  60. {
  61. if(a[i].f)
  62. {
  63. for(j=1;j<=k;j++)
  64. if(a[i].g[j]!=-1)
  65. a[i].sum+=a[i].g[j];
  66. }
  67. }
  68. sort(a+1,a+1+n,cmp);
  69. a[1].rank=1;
  70. for(i=2;i<=n;i++)
  71. {
  72. if(a[i].sum==a[i-1].sum)
  73. a[i].rank=a[i-1].rank;
  74. else
  75. a[i].rank=i;
  76. }
  77. for(i=1;i<=n;i++)
  78. {
  79. if(a[i].f)
  80. {
  81. printf("%d %05d %d",a[i].rank,a[i].id,a[i].sum);
  82. for(j=1;j<=k;j++)
  83. if(a[i].g[j]!=-1)
  84. printf(" %d",a[i].g[j]);
  85. else
  86. printf(" -");
  87. printf("\n");
  88. }
  89. }
  90. return 0;
  91. }

发表评论

表情:
评论列表 (有 0 条评论,164人围观)

还没有评论,来说两句吧...

相关阅读