1006. Sign In and Sign Out (25)

1.采用algorithm.h里面的sort函数,对时间进行排序,需要重写比较函数


//#include<string>
//#include <iomanip>
#include<vector>
#include <algorithm>
//#include<stack>
#include<set>
#include<queue>
#include<map>
//#include<unordered_set>
//#include<unordered_map>
//#include <sstream>
//#include "func.h"
//#include <list>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
using namespace std;
int time2Int(string s)
{
	int hour = (s[0] - '0') * 10 + s[1] - '0';
	int min = (s[3] - '0') * 10 + s[4] - '0';
	int sec = (s[6] - '0') * 10 + s[7] - '0';
	return hour * 3600 + min * 60 + sec;
}
struct people{
	int begin, end;
	string ID;
	people() :begin(0), end(0), ID(""){};
};
bool cmpBegin(const people&a, const people&b)
{
	if (a.begin < b.begin) return true;
	else return false;
}
bool cmpEnd(const people&a, const people&b)
{
	if (a.end > b.end) return true;
	else return false;
}
int main(void) {

	int n;
	cin >> n;
	vector<people> p(n);
	for (int i = 0; i < n; i++)
	{
		string a, b, c;
		cin >> a >> b >> c;
		p[i].ID = a;
		p[i].begin = time2Int(b);
		p[i].end = time2Int(c);
	}
	string first = "";
	sort(p.begin(), p.end(), cmpBegin);
	first = p[0].ID;
	sort(p.begin(), p.end(), cmpEnd);
	string last = p[0].ID;
	cout << first << " " << last << endl;
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值