PAT 甲级 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.

输入

Each input file contains one test case. For each case, the first line contains 3 positive integers, N ( ≤ 1 0 4 ) (≤10^4) (104), the total number of users, K (≤5), the total number of problems, and M ( ≤ 1 0 5 ) (≤10^5) (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.

输出

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.

思路

麻烦的排序题,照着题目要求排序

代码

#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;
int N, K, M;
typedef struct node {
    
    
	int id;
	int number;
	int score;
}Cord;
Cord cord[100100];
typedef struct NODE {
    
    
	int id;
	int score[10] = {
    
     0 };
	int all;
}Per;
Per per[10100];
int all_score[10] = {
    
     0 };
bool cmp(Cord a, Cord b)
{
    
    
	if (a.id != b.id)
	{
    
    
		return a.id < b.id;
	}
	if (a.number != b.number)
	{
    
    
		return a.number < b.number;
	}
	return a.score < b.score;
}
bool cmp2(Per a, Per b)
{
    
    
	
	if (a.all != b.all)
	{
    
    
		return a.all > b.all;
	}
	int man1 = 0, man2 = 0;
	for (int i = 1; i <= K; i++)
	{
    
    
		if (a.score[i] == all_score[i])
		{
    
    
			man1++;
		}
		if (b.score[i] == all_score[i])
		{
    
    
			man2++;
		}
	}
	if (man1 != man2)
	{
    
    
		return man1 > man2;
	}
	else
	{
    
    
		return a.id < b.id;
	}
}
int main()
{
    
    
	
	cin >> N >> K >> M;
	for (int i = 1; i <= K; i++)
	{
    
    
		cin >> all_score[i];
	}
	for (int i = 0; i < M; i++)
	{
    
    
		cin >> cord[i].id >> cord[i].number >> cord[i].score;
	}
	//sort(cord, cord + M, cmp);
	for (int i = 1; i <= N; i++)
	{
    
    
		per[i].id = i;
		for (int j = 1; j <= K; j++)
		{
    
    
			per[i].score[j] = -2;
		}
	}
	for (int i = 0; i < M; i++)
	{
    
    
		if (per[cord[i].id].score[cord[i].number] < cord[i].score)
		{
    
    
			per[cord[i].id].score[cord[i].number] = cord[i].score;
		}
	}
	for (int i = 1; i <= N; i++)
	{
    
    
		int temp = 0;
		for (int j = 1; j <= K; j++)
		{
    
    
			if (per[i].score[j] <= 0)
			{
    
    
				temp += 0;
			}
			else
			{
    
    
				temp += per[i].score[j];
			}
		}
		per[i].all = temp;
	}
	sort(per + 1, per + N + 1, cmp2);
	int rank = 1;
	printf("%d %05d %d", rank, per[1].id,per[1].all);
	for (int j = 1; j <= K; j++)
	{
    
    
		if (per[1].score[j] == -2)
		{
    
    
			printf(" -");
		}
		else if (per[1].score[j] == -1)
		{
    
    
			printf(" 0");
		}
		else
		{
    
    
			printf(" %d", per[1].score[j]);
		}
	}
	cout << endl;
	for (int i = 2; i <= N; i++)
	{
    
    
		if (per[i].all == 0)
		{
    
    
			int temp = 0;
			for (int j = 1; j <= K; j++)
			{
    
    
				if (per[i].score[j] >= 0)
				{
    
    
					temp = 1;
					break;
				}
			}
			if (temp == 0)
			{
    
    
				continue;
			}
		}
		if (per[i].all != per[i - 1].all)
		{
    
    
			rank=i;
		}
		printf("%d %05d %d", rank, per[i].id, per[i].all);
		for (int j = 1; j <= K; j++)
		{
    
    
			if (per[i].score[j] == -2)
			{
    
    
				printf(" -");
			}
			else if (per[i].score[j] == -1)
			{
    
    
				printf(" 0");
			}
			else
			{
    
    
				printf(" %d", per[i].score[j]);
			}
		}
		cout << endl;
	}

}

猜你喜欢

转载自blog.csdn.net/qq_45478482/article/details/120082703