踩坑:最后一个测试点没过,直接用long long是输出不了前导0的!!!
这个printf("%013lld")就很有灵性了
#include<cstdio>
#include<cstring>
#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
struct student
{
int score;
long long registration_number;
int final_rank;
int location_num;
int local_rank;
}stu[35000];
bool cmp1(student s1, student s2)
{
return s1.score > s2.score;
}
bool cmp2(student s1, student s2)
{
if (s1.final_rank != s2.final_rank)
return s1.final_rank < s2.final_rank;
else
return s1.registration_number < s2.registration_number;
}
int main()
{
int n;
int location[110];
scanf("%d", &n);
int count = 0;
for(int i = 0; i < n; i++)
{
int num;
scanf("%d", &num);
for(int j = count; j < count + num; j++)
{
scanf("%lld %d", &stu[j].registration_number, &stu[j].score);
stu[j].location_num = i + 1;
}
sort(stu+count, stu+count+num, cmp1);
for(int j = count; j < count + num; j++)
{
if(j == count)
{
stu[j].local_rank = j - count + 1;
}
else
{
if(stu[j].score == stu[j-1].score)
stu[j].local_rank = stu[j-1].local_rank;
else
stu[j].local_rank = j - count + 1;
}
}
count = count + num;
}
sort(stu, stu + count, cmp1);
for(int i = 0; i < count; i++)
{
if(i == 0)
{
stu[i].final_rank = i + 1;
}
else
{
if(stu[i].score == stu[i-1].score)
stu[i].final_rank = stu[i-1].final_rank;
else
stu[i].final_rank = i + 1;
}
}
sort(stu, stu + count, cmp2);
printf("%d\n", count);
for(int i = 0; i < count; i++)
{
printf("%013lld %d %d %d\n", stu[i].registration_number, stu[i].final_rank, stu[i].location_num, stu[i].local_rank);
}
return 0;
}