PAT 甲级 1025 PAT Ranking

踩坑:最后一个测试点没过,直接用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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值