#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
struct student
{
char id[15];
int score;
int location;
int localrank;
int finalrank;
};
bool loccmp(student x,student y)
{
if (x.score!=y.score){return x.score>y.score;}
else {return strcmp(x.id,y.id)<0;}
}
bool finalcmp(student x,student y)
{
if (x.score!=y.score){return x.score>y.score;}
else {return strcmp(x.id,y.id)<0;}
}
int main()
{
student stu[30010];
int n;
int num=0;
cin>>n;
for (int l=0;l<n;l++)
{
int k;
cin>>k;
int begin=num;
for (int i=0;i<k;i++)
{
cin>>stu[num].id>>stu[num].score;
stu[num].location=l+1;
num++;
}
int end=num;
sort(stu+begin,stu+end,loccmp);
for (int j=begin;j<end;j++)
{
stu[j].localrank=j+1-begin;
if ( ( j>=1) && (stu[j].score==stu[j-1].score)) {stu[j].localrank=stu[j-1].localrank;}
}
}
sort(stu,stu+num,finalcmp);
for (int j=0;j<num;j++)
{
stu[j].finalrank=j+1;
if ( ( j>=1) && (stu[j].score==stu[j-1].score)) {stu[j].finalrank=stu[j-1].finalrank;}
}
cout<<num<<endl;
for (int i=0;i<num;i++)
{
cout<<stu[i].id<<" "<<stu[i].finalrank<<" "<<stu[i].location<<" "<<stu[i].localrank<<endl;
}
system("pause");
return 0;
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
struct student
{
char id[15];
int score;
int location;
int localrank;
int finalrank;
};
bool loccmp(student x,student y)
{
if (x.score!=y.score){return x.score>y.score;}
else {return strcmp(x.id,y.id)<0;}
}
bool finalcmp(student x,student y)
{
if (x.score!=y.score){return x.score>y.score;}
else {return strcmp(x.id,y.id)<0;}
}
int main()
{
student stu[30010];
int n;
int num=0;
cin>>n;
for (int l=0;l<n;l++)
{
int k;
cin>>k;
int begin=num;
for (int i=0;i<k;i++)
{
cin>>stu[num].id>>stu[num].score;
stu[num].location=l+1;
num++;
}
int end=num;
sort(stu+begin,stu+end,loccmp);
for (int j=begin;j<end;j++)
{
stu[j].localrank=j+1-begin;
if ( ( j>=1) && (stu[j].score==stu[j-1].score)) {stu[j].localrank=stu[j-1].localrank;}
}
}
sort(stu,stu+num,finalcmp);
for (int j=0;j<num;j++)
{
stu[j].finalrank=j+1;
if ( ( j>=1) && (stu[j].score==stu[j-1].score)) {stu[j].finalrank=stu[j-1].finalrank;}
}
cout<<num<<endl;
for (int i=0;i<num;i++)
{
cout<<stu[i].id<<" "<<stu[i].finalrank<<" "<<stu[i].location<<" "<<stu[i].localrank<<endl;
}
system("pause");
return 0;
}
1.注意PAT的排序规则