1006サインインとサインアウト(25ポイント)「PTAクラスAトレーニング」

この質問は非常に単純で、最初のものを探し、最後のものを探します。アイデアは非常に明確です。

コード:

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1010;
struct node{
	char name[20];
	char betime[20];
	char endtime[20];
}person[N];

int n;

bool cmp1(struct node a,struct node b){
	return strcmp(a.betime, b.betime)<0?true:false;
}
bool cmp2(struct node a,struct node b){
	return strcmp(a.endtime, b.endtime)>0?true:false;
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>person[i].name>>person[i].betime>>person[i].endtime;
	}
	sort(person+1,person+1+n,cmp1);
	printf("%s",person[1].name);
	printf(" ");
	sort(person+1,person+1+n,cmp2);
	printf("%s",person[1].name);
	printf("\n");
	return 0;
}
 

ただし、ガチョウは次のことに注意を払う必要があります。

//求一个从小到大的字符串的写法
bool cmp1(struct node a,struct node b){
	return strcmp(a.betime, b.betime)<0?true:false;
}

おすすめ

転載: blog.csdn.net/weixin_60789461/article/details/122886635