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;
}