hdoj 1234 step 1.3.4 开门人和关门人

等人的过程中写的。。。这题考的应该就是结构体排序吧。

复习sort函数,,自定义一个比较函数重载运算符。从而达到题目所要求的。。还有就是strcmp字符串比较   strcmp(s1,s2) 当s1<s2时返回负数,当s1==s2时 返回值==0,当s1>s2时返回正数。。 应该就这两点吧。。。


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct record
{
	char card[20];
	char come[20];
	char left[20]; 
}s[1005];
int cmp1(record a,record b)
{
	return strcmp(a.come,b.come) < 0; //升序排 
}
int cmp2(record a,record b)
{
	return strcmp(a.left,b.left) > 0; //降序排 
}
int main ()
{
	int n,i;
	scanf("%d",&n);
	while(n--)
	{
		int m;
		scanf("%d",&m);
		for(i=0;i<m;i++)
			scanf("%s%s%s",s[i].card,s[i].come,s[i].left);
		sort(s,s+m,cmp1);
		printf("%s ",s[0].card);
		sort(s,s+m,cmp2);
		printf("%s\n",s[0].card);
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值