7月四日
完成了数据结构的第二个题目;老板的作息表,这是我的源代码
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
struct node{
string begin, end;
}times[100001];
bool cmp(const node& t1,const node& t2) {
return t1.begin < t2.begin;
}
int main()
{
int num;
cin >> num;
char c;
for (int i = 0; i < num; i++) {
cin >> times[i].begin >> c >> times[i].end;
}
sort(times, times + num, cmp);
if (times[0].begin != "00:00:00") {
if (num != 0) {
cout << "00:00:00" << " - " << times[0].begin << endl;
}
else {
cout << "00:00:00" << " - " << "23:59:59" << endl;
}
}
if (num > 1) {
for (int i = 0; i < num - 1; i++) {
if (times[i].end != times[i + 1].begin) {
cout << times[i].end << " - " << times[i + 1].begin << endl;
}
}
}
if (num >= 1) {
if (times[num - 1].end != "23:59:59") {
cout << times[num - 1].end << " - " << "23:59:59" << endl;
}
}
}