AcWing 1502. PAT 排名
原题链接
中等
作者:
songpx
,
2021-02-13 23:57:15
,
所有人可见
,
阅读 367
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 110;
struct Student
{
string id;
int grade, location_number, final_rank, local_rank;
bool operator< (const Student & s) const
{
if (grade != s.grade) return grade > s.grade;
if (id != s.id) return id < s.id;
}
};
vector<Student> locations[N];
vector<Student> alls;
int main()
{
int n;
cin >> n;
//处理所有地区
for (int i = 1; i <= n; i++)
{
int m;
cin >> m;
//处理当前区域
for (int j = 0; j < m; j++)
{
string id;
int grade;
cin >> id >> grade;
locations[i].push_back({id, grade, i});
}
sort(locations[i].begin(), locations[i].end());
for (int j = 0; j < m; j++)
{
if (!j || locations[i][j].grade != locations[i][j - 1].grade)
locations[i][j].local_rank = j + 1;
else
locations[i][j].local_rank = locations[i][j - 1].local_rank;
alls.push_back(locations[i][j]);
}
}
sort(alls.begin(), alls.end());
for (int j = 0; j < alls.size(); j++)
{
if (!j || alls[j].grade != alls[j - 1].grade)
alls[j].final_rank = j + 1;
else
alls[j].final_rank = alls[j - 1].final_rank;
}
cout << alls.size() << endl;
for (int i = 0; i < alls.size(); i++)
{
cout << alls[i].id << ' ' << alls[i].final_rank << ' ' << alls[i].location_number << ' ' << alls[i].local_rank << endl;
}
return 0;
}