PAT (Advanced) 1075. PAT Judge (25)

2196 ワード

次のコードの最後の3点テストのサンプルはずっと合格できず、とても無言でした.もしあなたがその中のバグを見つけたら、メッセージを教えてください.ありがとうございます!
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>

using namespace std;

struct User
{
	int user_id;
	int rank;
	int total_score;
	int problem_score[5];
	bool tried_to[5];
	bool perfectly_solved[5];
	int total_tried;
	int total_perfect;
}user[10001];

bool cmp(const User &a, const User &b)
{
	if (a.total_score != b.total_score)
		return a.total_score > b.total_score;
	else
	{
		if (a.total_perfect != b.total_perfect)
			return a.total_perfect > b.total_perfect;
		else
			return a.user_id < b.user_id;
	}
}

int main()
{
	freopen("in.txt", "r", stdin);
	int N, K, M;
	cin >> N >> K >> M;
	int *full_mark = new int[K];
	for (int i = 0; i < K; i++)
		cin >> full_mark[i];
	int u_id, p_id, part_score;
	for (int i = 0; i < M; i++)
	{
		cin >> u_id >> p_id >> part_score;
		user[u_id - 1].user_id = u_id - 1;
		if (part_score != -1)
		{
			if (part_score > user[u_id - 1].problem_score[p_id - 1])
			{
				user[u_id - 1].total_score = user[u_id - 1].total_score - user[u_id - 1].problem_score[p_id - 1] + part_score;
				user[u_id - 1].problem_score[p_id - 1] = part_score;
			}	
			if (part_score == full_mark[p_id - 1])
				user[u_id - 1].perfectly_solved[p_id - 1] = true;
			user[u_id - 1].total_tried++;
		}
		user[u_id - 1].tried_to[p_id - 1] = true;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < K; j++)
		{
			if (user[i].perfectly_solved[j] == true)
			user[i].total_perfect++;
		}
	}
	sort(user, user + N, cmp);
	user[0].rank = 0;
	for (int i = 1; i < N; i++)
	{
		if (user[i].total_score == user[i - 1].total_score)
			user[i].rank = user[i - 1].rank;
		else
			user[i].rank = i;
	}
	int i = 0;
	while (user[i].total_tried > 0)
	{
		printf("%d %05d %d", user[i].rank + 1, user[i].user_id + 1, user[i].total_score);
		for (int j = 0; j < K; j++)
		{
			if (user[i].tried_to[j] == true)
				printf(" %d", user[i].problem_score[j]);
			else
				printf(" -");
		}
		printf("
"); i++; } }