基础实验7-2.4 PAT排名汇总 (25 分)

基础实验7-2.4 PAT排名汇总 (25 分)

结构体排序

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
struct student{
	string a;
	int b,c,d;
}s[200000];
bool cmp1(struct student x,struct student y)
{
	if(x.b>y.b)
		return 1;
	else	
		return 0;
}
bool cmp2(struct student x,struct student y)
{
	if(x.b>y.b)
		return 1;
	else if(x.b==y.b){
		if(x.a<y.a)
			return 1;
	}
	return 0;
}
int main()
{
    int n,k,i=0,ret=0;
    cin>>n;
    while(n--)
    {
    	ret++;
    	cin>>k;
    	getchar();
    	for(int j=i;j<i+k;++j)
    	{
			cin>>s[j].a>>s[j].b;
			s[j].c=ret;
    	}
    	sort(s+i,s+i+k,cmp1);
    	int p=1,net=0;
    	s[i].d=p;
    	for(int j=i+1;j<i+k;++j)
    	{
    		if(s[j].b<s[j-1].b)
    		{
    			p=p+1+net;
				s[j].d=p;
				net=0;
    		}
    		else{
    			s[j].d=p;
    			net++;
			}
		}
    	i+=k;
	}
	sort(s,s+i,cmp2);
	int p=1,net=0;
	cout<<i<<endl;
	cout<<s[0].a<<" "<<p<<" "<<s[0].c<<" "<<s[0].d<<endl;
	for(int j=1;j<i;++j)
    {
    	if(s[j].b<s[j-1].b)
    	{
    		p=p+1+net;
			net=0;
    	}
    	else{
    		net++;
		}
		cout<<s[j].a<<" "<<p<<" "<<s[j].c<<" "<<s[j].d<<endl;
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值