1028. List Sorting (25)


1028. List Sorting (25)


#include <string.h>
#include <algorithm>
#include <stdio.h>
class cstudent
{
public:
	int id;
	char name[10];
	int score;
	friend bool IdCmp(const cstudent &s1,const cstudent &s2);
	friend bool NameCmp(const cstudent &s1,const cstudent &s2);
	friend bool ScoreCmp(const cstudent &s1,const cstudent &s2);
};
bool IdCmp(const cstudent &s1,const cstudent &s2)
{
	return s1.id<s2.id;
}
bool NameCmp(const cstudent &s1,const cstudent &s2)
{
	int icmp=strcmp(s1.name,s2.name);
	if(icmp==0) return s1.id<s2.id;
	else return icmp<0;
}
bool ScoreCmp(const cstudent &s1,const cstudent &s2)
{
	if(s1.score==s2.score) return s1.id<s2.id;
	else return s1.score<s2.score;
}
class CA 
{
public:
	enum{N=100010};
	void run();
	cstudent vs[N];
};

void CA::run()
{
	int n,k;
	cstudent stu;
	scanf("%d%d",&n,&k);
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d%s%d",&stu.id,stu.name,&stu.score);
		vs[i]=stu;
	}
	if(k==1)
	{
		std::sort(vs,vs+n,IdCmp);
	}
	else if(k==2)
	{
		std::sort(vs,vs+n,NameCmp);
	}
	else if(k==3)
	{
		std::sort(vs,vs+n,ScoreCmp);
	}
	for(i=0;i<n;i++)
	{
		printf("%06d %s %d\n",vs[i].id,vs[i].name,vs[i].score);
	}
}


int main()
{
//	freopen("test.in","r",stdin);
	CA *a=new CA;
	a->run();
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值