10-排序5 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:
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:
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 -
#include<stdio.h>
#include<stdlib.h>
struct User {
int UserId;
int PerfectNum;
int Question[6];
struct User* Next;
int TotalScore;
int CompileFlag;
};
struct User* Initialize_User(int N, int K);
void GetInformation(struct User* AllUser, int M, int N, int K,int*A);
void Load(struct User** Buckets, struct User* AllUser, int N);
void PrintUser(struct User** Buckets, int K);
void PrintUserId(int Num);
int main()
{
int N, K, M;
int Score[6];
scanf("%d %d %d", &N, &K, &M);
for (int i = 1; i <= K; i++)
{
scanf("%d", Score + i);
}
struct User* AllUser = Initialize_User(N, K);
GetInformation(AllUser, M, N, K, Score);
struct User** Buckets = (struct User**)malloc(sizeof(struct User*) * 101);//0到100分
for (int i = 0; i <= 100; i++)
{
Buckets[i] = (struct User*)malloc(sizeof(struct User));
Buckets[i]->Next = NULL;
}
Load(Buckets, AllUser, N);
PrintUser(Buckets,K);
}
struct User* Initialize_User(int N, int K)
{
struct User* AllUser = (struct User*)malloc(sizeof(struct User) * (N + 1));
for (int i = 1; i <= N; i++)
{
AllUser[i].UserId = i;
AllUser[i].PerfectNum = 0;
AllUser[i].Next = NULL;
AllUser[i].TotalScore =-1;//总分都为-1以区分编没编译通过
AllUser[i].CompileFlag = 0;
for (int j = 1; j <= K; j++)
{
AllUser[i].Question[j] = -1;//问题得分都为-1
}
}
return AllUser;
}
void GetInformation(struct User* AllUser, int M,int N,int K,int*A)
{
int Index, QuestionId, Score,Temp;
Temp = 0;
for (int i = 0; i < M; i++)
{
scanf("%d %d %d", &Index, &QuestionId, &Score);
if (AllUser[Index].Question[QuestionId] < Score)
{
AllUser[Index].Question[QuestionId] = Score;
AllUser[Index].CompileFlag = 1;
}
else if (AllUser[Index].Question[QuestionId]==Score&&Score==-1)
{
AllUser[Index].Question[QuestionId] =0;
}
}
for (int i = 1; i <= N; i++)//获取总分
{
for (int j = 1; j <= K; j++)
{
if (AllUser[i].Question[j] != -1)
{
Temp = Temp + AllUser[i].Question[j];
}
if (AllUser[i].Question[j] == A[j])
{
AllUser[i].PerfectNum++;
}
}
AllUser[i].TotalScore = Temp;
Temp = 0;
}
}
void Load(struct User** Buckets, struct User* AllUser,int N)
{
struct User* Head;
struct User* Next;
int Flag = 0;
for (int i = 1; i <= N; i++)
{
if (AllUser[i].CompileFlag==1)
{
Head = Buckets[AllUser[i].TotalScore];
Next = Head->Next;
while (Flag == 0 && Next)
{
if (AllUser[i].PerfectNum > Next->PerfectNum)
{
Head->Next = (AllUser + i);
(AllUser + i)->Next = Next;
Flag = 1;
}
else if (AllUser[i].PerfectNum == Next->PerfectNum)
{
if (AllUser[i].UserId < Next->UserId)
{
Head->Next = (AllUser + i);
(AllUser + i)->Next = Next;
Flag = 1;
}
else
{
Head = Next;
Next = Next->Next;
}
}
else
{
Head = Next;
Next = Next->Next;
}
}
if (Flag == 1)
Flag = 0;
else
{
Head->Next = (AllUser + i);
}
}
}
}
void PrintUser(struct User** Buckets,int K)
{
struct User* Ptr;
int Total=0;
int Flag = 0;
int Rank=0;
for (int i = 100; i >= 0; i--)
{
Ptr = Buckets[i]->Next;
while (Ptr)
{
if (Flag == 0)
{
Rank = Total+1;
Flag = 1;
}
Total++;
printf("%d ", Rank);
PrintUserId(Ptr->UserId);
printf("%d ", Ptr->TotalScore);;
for (int j = 1; j < K; j++)
{
if (Ptr->Question[j] == -1)
printf("- ");
else
{
printf("%d ", Ptr->Question[j]);
}
}
if (Ptr->Question[K] == -1)
printf("-");
else
{
printf("%d", Ptr->Question[K]);
}
printf("\n");
Ptr = Ptr->Next;
}
Flag = 0;
}
}
void PrintUserId(int Num)
{
if (Num < 10)
{
printf("0000%d ", Num);
}
else if (Num >= 10 && Num < 100)
{
printf("000%d ", Num);
}
else if (Num >= 100 && Num < 1000)
{
printf("00%d ", Num);
}
else if (Num >= 1000 && Num < 10000)
{
printf("0%d ", Num);
}
else
{
printf("%d ", Num);
}
}

该文介绍了一种用于PAT比赛的排名系统实现方法。输入包含用户数、问题数和提交数,以及每个问题的满分。程序首先初始化用户结构体,接着获取每个提交的信息,计算用户总分和完美解决问题的数量。然后,根据总分和完美解决的问题数量对用户进行排序,并输出排名及各问题得分。输出结果按排名升序、完美问题数量降序、用户ID升序排列。
210

被折叠的 条评论
为什么被折叠?



