PAT 1075. PAT Judge (模拟题)

n个用户(1...n), k门课程(1...k), m次提交,模拟PAT排名。


总得分高的排名前;

总得分相等,满分题数多的排名前;

满分题数仍相等,id小的排名前。


从未提交 或 提交代码从未通过编译的用户不予输出。

注意到,输出用户信息时,该用户从未提交过的题目输出为"-"; 提交过未得到分的(得分为0或编译未通过的),则输出"0".


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
//#include <map>

using namespace std;

struct User;

int n, k, m;
int p[6];

struct User
{
	int m_rank;
	int m_id;
	int m_score[6];
	int m_submit_cnt[6];
	User()
	{
		for (int i = 1; i <= 5; ++ i)
		{
			m_score[i] = -1;
			m_submit_cnt[i] = 0;
		}
	}
	friend bool operator< (const User& a, const User& b)
	{
		int aa = a.get_tot_score();
		int bb = b.get_tot_score();
		if (aa != bb)
		{
			return aa > bb;
		} else if (a.get_perfect_num() != b.get_perfect_num())
		{
			return a.get_perfect_num() > b.get_perfect_num();
		} else
		{
			return a.m_id < b.m_id;
		}
	}
	int get_tot_score() const 
	{
		int ret = -1;
		for (int i = 1; i <= k ; ++ i)
		{
			if (m_score[i] != -1)
			{
				// 最终可以让从未提交、或从未通过编译的用户排在最末尾
				if (ret == -1)
				{
					ret = 0;
				}
				ret += m_score[i];
			}
		}
		return ret;
	}
	int get_perfect_num() const 
	{
		int ret = 0;
		for (int i = 1; i <= k; ++ i)
		{
			if (m_score[i] == p[i])
			{
				++ ret;
			}
		}
		return ret;
	}
	bool print() const 
	{
		bool should_print = false;
		for (int i = 1; i <= k; ++ i)
		{
			if (m_score[i] != -1)
			{
				should_print = true;
				break;
			}
		}
		if (should_print == false)
		{
			return false;
		}
		printf("%d %05d %d", m_rank, m_id, get_tot_score());
		for (int i = 1; i <= k; ++ i)
		{
			if (m_submit_cnt[i] > 0)
			{
				if (m_score[i] == -1)
				{
					printf(" 0");
				} else 
				{
					printf(" %d", m_score[i]);
				}
			} else
			{
				printf(" -");
			}
		}
		printf("\n");

		return true;
	}
};

User user[10010];

int main()
{
	int course_id, score, user_id;

	scanf("%d%d%d", &n, &k, &m);
	for (int i = 1; i <= k; ++ i)
	{
		scanf("%d", p+i);
	}
	for (int i = 0; i < m; ++ i)
	{
		scanf("%d%d%d", &user_id, &course_id, &score);
		user[user_id].m_id = user_id;
		++ user[user_id].m_submit_cnt[course_id];
		if (user[user_id].m_score[course_id] < score)
		{
			user[user_id].m_score[course_id] = score;	
		}
	}

	sort(user+1, user+n+1);

	user[1].m_rank = 1;
	for (int i = 2; i <= n; ++ i)
	{
		if (user[i].get_tot_score() == user[i-1].get_tot_score())
		{
			user[i].m_rank = user[i-1].m_rank;
		} else
		{
			user[i].m_rank = i;
		}
	}

	for (int i = 1; i <= n; ++ i)
	{
		if (user[i].print() == false)
		{
			break;
		}
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值