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 - 思路:不用思路 水题。 注意一点,当计算满分的时候有的人肯能多次提交满分,导致排名考前,这是一个很明显的bug 本次代码写的很乱。。。
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 using namespace std; 5 #define MAX 10010 6 struct Record 7 { 8 int id; 9 int grade[6]; 10 bool flag[6]; 11 int submit; 12 int total; 13 int rank; 14 bool status; 15 int solve; 16 }Record[MAX]; 17 int full[6]; 18 bool cmp(struct Record A,struct Record B) 19 { 20 if(!A.status||!B.status) 21 return A.status; 22 else if(A.total!=B.total) 23 return A.total>B.total; 24 else if(A.solve!=B.solve) 25 return A.solve>B.solve; 26 else 27 return A.id<B.id; 28 } 29 30 void Print(int num,int K) 31 { 32 bool flag=false; 33 //检验是否提交任意一个解决方案 34 for(int i=1;i<=K;i++) 35 { 36 if(Record[num].flag[i]) 37 { 38 flag=true; 39 break; 40 } 41 } 42 if(!flag) 43 return; 44 printf("%d %05d %d",Record[num].rank,Record[num].id,Record[num].total); 45 for(int i=1;i<=K;i++) 46 { 47 if(!Record[num].flag[i]) 48 { 49 printf(" -"); 50 } 51 else 52 printf(" %d",Record[num].grade[i]); 53 } 54 putchar(‘\n‘); 55 } 56 57 58 int main(int argc, char *argv[]) 59 { 60 //初始化 61 for(int i=0;i<MAX;i++) 62 { 63 for(int j=1;j<=5;j++) 64 { 65 Record[i].flag[j]=false; 66 Record[i].grade[j]=-2; 67 } 68 Record[i].submit=0; 69 Record[i].total=-2; 70 Record[i].status=false; 71 Record[i].solve=0; 72 } 73 int N,K,M; 74 scanf("%d%d%d",&N,&K,&M); 75 for(int i=1;i<=K;i++) 76 scanf("%d",&full[i]); 77 //都有成绩 78 for(int i=0;i<M;i++) 79 { 80 int grade,index; 81 int id; 82 scanf("%d",&id); 83 scanf("%d",&index); 84 scanf("%d",&grade); 85 if(grade==-1&&Record[id].grade[index]==-2) 86 { 87 Record[id].id=id; 88 Record[id].grade[index]=0; 89 Record[id].flag[index]=true; 90 continue; 91 } 92 else 93 { 94 //一个题目提交多次 有改动 此处需要敏锐 95 if(full[index]==grade&&Record[id].grade[index]!=grade) 96 Record[id].solve++; 97 Record[id].id=id; 98 if(grade>Record[id].grade[index]) 99 Record[id].grade[index]=grade; 100 Record[id].flag[index]=true; 101 Record[id].submit++; 102 Record[id].status=true; 103 } 104 105 } 106 //计算总成绩 107 for(int i=0;i<MAX;i++) 108 { 109 if(Record[i].submit!=0) 110 { 111 int sum=0; 112 for(int j=1;j<=K;j++) 113 { 114 if(Record[i].flag[j]) 115 { 116 if(Record[i].grade[j]!=-1) 117 sum+=Record[i].grade[j]; 118 } 119 120 } 121 Record[i].total=sum; 122 } 123 } 124 sort(Record,Record+MAX,cmp); //此处耽误了很多。 125 Record[0].rank=1; 126 for(int i=1;i<=N;i++) 127 { 128 if(Record[i].total==Record[i-1].total) 129 Record[i].rank=Record[i-1].rank; 130 else 131 Record[i].rank=i+1; 132 } 133 for(int i=0;i<N;i++) 134 { 135 Print(i,K); 136 } 137 return 0; 138 }