//
// main.cpp
// PAT_1025. PAT Ranking
//
// Created by wjq on 17/4/11.
// Copyright © 2017年 wjq. All rights reserved.
//
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
struct student
{
string id;
int grade,groupID,groupRank,Rank;
}s[30005];
int groupNum;
bool cmp(student a,student b)
{
if(a.grade==b.grade)
return a.id<b.id;
return a.grade>b.grade;
}
int main(int argc, const char * argv[])
{
cin>>groupNum;
int K,j=0;
for(int i=1;i<=groupNum;i++)
{
int start=j;
cin>>K;
while(K--)
{
cin>>s[j].id>>s[j].grade;
s[j].groupID=i;
j++;
}
int end=j;
sort(s+start,s+end,cmp);
for(int i=start;i<end;i++)
s[i].groupRank=i-start+1;
for(int i=start+1;i<end;i++)
if(s[i].grade==s[i-1].grade)
s[i].groupRank=s[i-1].groupRank;
}
sort(s,s+j,cmp);
for(int i=0;i<j;i++)
s[i].Rank=i+1;
for(int i=1;i<j;i++)
{
if(s[i].grade==s[i-1].grade)
s[i].Rank=s[i-1].Rank;
}
cout<<j<<endl;
for(int i=0;i<j;i++)
cout<<s[i].id<<" "<<s[i].Rank<<" "<<s[i].groupID<<" "<<s[i].groupRank<<endl;
return 0;
}
简单题..