PAT A 1025 PAT Ranking (25分)

1025 PAT Ranking (25分)

吐槽

请问我可以在排名系统里给自己留个特殊判定吗()

以及希望自己记住以后所有定位数ID都用string不管是不是全数字不管塞不塞得进int省的又因为起头的0出问题……

逻辑

没啥多的,用结构体和自排序队列priority_queue,信息扔进队列自己会排好的,再一个个拿出来处理一下排名就行了。

测点的坑

最后一个测点里有以0开头的ID。我一开始又忘了要固定位数ID输出so……
看那个用时和内存量这个测点里人数估计还是题设上限值。不过数组溢出什么的和我这个用队列的是没啥关系的啦~

题目

代码

#include<iostream>
#include<queue>
#include<algorithm>
#include<iomanip>

using namespace std;

typedef struct Testee
{
	long long int ID;
	int score;
	int location;
	int localrank;
	friend bool operator < (struct Testee t1, struct Testee t2)
	{
		if (t2.score > t1.score)
			return true;
		else if (t2.score == t1.score)
		{
			if (t2.ID < t1.ID)
				return true;
		}
		return false;
	}
}testee;



int main()
{
	int n;
	cin >> n;
	priority_queue<Testee> ql;
	priority_queue<Testee> qf;
	int m;
	int i, ii;
	int score, rank;
	testee t;
	int count = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> m;
		t.location = i;
		for (ii = 0; ii < m; ii++)
		{
			cin >> t.ID >> t.score;
			count++;
			ql.push(t);
		}
		score = ql.top().score;
		rank = 1;
		for (ii = 1; ii <= m; ii++)
		{
			t = ql.top();
			if (t.score != score)
			{
				rank = ii;
				score = t.score;
			}
			t.localrank = rank;
			qf.push(t);
			ql.pop();
		}
	}
	score = qf.top().score;
	rank = 1;
	i = 1;
	cout << count << endl;
	while (!qf.empty())
	{
		t = qf.top();
		if (t.score != score)
		{
			rank = i;
			score = t.score;
		}
		i++;
		cout << setw(13) << setfill('0') << t.ID;
		cout<< " " << rank << " " << t.location << " " << t.localrank << endl;
		qf.pop();
	}
	cin >> n;
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值