PAT 甲级 1006 Sign In and Sign Out

#include 
using namespace std;

struct Record
{
	string id, time_in, time_out;
	Record(string id, string time_in, string time_out):
		id(id), time_in(time_in), time_out(time_out){}
};

int main()
{
	// freopen("1006.data", "r", stdin);
	int M; cin >> M;
	string id, time_in, time_out;
	cin >> id >> time_in >> time_out;
	Record tmp(id, time_in, time_out);
	Record first = tmp, last = tmp;
	for(int i = 1; i < M; i++)
	{
		cin >> tmp.id >> tmp.time_in >> tmp.time_out;
		if(tmp.time_in < first.time_in)
			first = tmp;
		if(tmp.time_out > last.time_out)
			last = tmp;
	}
	cout << first.id << " " << last.id << endl;
}

你可能感兴趣的:(PAT)