题目传送门:https://pintia.cn/problem-sets/994805342720868352/problems/994805474338127872
思路:结构体模拟
注意排序的条件
#include <iostream>
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define scl(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define prs(x) printf("%s\n",(x))
#define prs(x) printf("%s\n",(x))
#define PII pair<int,int>
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
using namespace std;
int n,k;
const int maxn = 100005;
struct node{
char name[15];
int grade;
int loc;
int r1,r2;
}a[maxn];
bool cmp(node a,node b){
return a.grade==b.grade ? strcmp(a.name,b.name)<0 : a.grade>b.grade;
}
int main() {
sca(n);
int cnt=0,be=0,ed=0;
rep(z,0,n){
be=cnt;
sca(k);
ed+=k;
rep(i,0,k){
scs(a[cnt].name),sca(a[cnt].grade);
a[cnt++].loc=z+1;
}
sort(a+be,a+ed,cmp);
rep(i,0,k){
if(i>0&&a[be+i].grade==a[be+i-1].grade)
a[be+i].r1=a[be+i-1].r1;
else
a[be+i].r1=i+1;
}
}
sort(a,a+cnt,cmp);
pri(cnt);
rep(i,0,cnt){
if(i>0&&a[i].grade==a[i-1].grade)
a[i].r2=a[i-1].r2;
else
a[i].r2=i+1;
cout<<a[i].name <<" " <<a[i].r2<<" "<<a[i].loc<<" "<<a[i].r1<<endl;
}
}