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;
}


你可能感兴趣的:(hdoj 1234 step 1.3.4 开门人和关门人)