#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct student {
string registration_number;
int score, final_rank, local_rank, location_number;
};
bool cmp(student s1, student s2);
int main()
{
int N;
scanf("%d", &N);
vector<student>stu, total_stu;
student current_stu;
int* KS = new int[N]; //N个记录,记录各个组的考试人数
for (int i = 0; i < N; i++) {
scanf("%d", &KS[i]);//输入第i+1个组的考试人数
for (int j = 0; j < KS[i]; j++) {
cin >> current_stu.registration_number >> current_stu.score;
current_stu.location_number = i + 1;
stu.push_back(current_stu);
}
sort(stu.begin(), stu.begin() + KS[i], cmp);
int rank = 1;
for (int k = 0; k < KS[i]; k++) {
if (k > 0 && stu[k].score != stu[k - 1].score)rank=k+1;
stu[k].local_rank = rank;
}
total_stu.insert(total_stu.end(), stu.begin(), stu.end()); //s将各个考区的记录插入总记录
stu.clear();//清空第i+1个区的记录
}
sort(total_stu.begin(), total_stu.end(), cmp);
int rank = 1;
for (int k = 0; k < total_stu.size(); k++) {
if (k > 0 && total_stu[k].score != total_stu[k - 1].score)rank=k+1;
total_stu[k].final_rank = rank;
}
cout<<total_stu.size()<<endl;
for (vector<student>::iterator it = total_stu.begin(); it != total_stu.end(); it++) {
if((it+1)==total_stu.end())
cout << (*it).registration_number << " " << (*it).final_rank << " " << (*it).location_number << " " << (*it).local_rank;
else
cout << (*it).registration_number << " " << (*it).final_rank << " " << (*it).location_number << " " << (*it).local_rank << endl;
}
return 0;
}
bool cmp(student s1, student s2)
{
if (s1.score != s2.score)return s1.score > s2.score;
else return s1.registration_number < s2.registration_number;
}
运用sort vector的一些特性会非常方便