L2-042 The boss’s schedule is super simple (PTA Ladder Match)

 

Someone posted a boss's schedule on Sina Weibo, indicating that he gets up at 4:30 every day. But immediately some sharp-eyed netizens asked: This timetable is incomplete. What do you do from nine in the morning to one in the afternoon?

This question asks you to write a program to check any timetable and find the time period that is not written in it.

Input format:

The first line of input gives a positive integer N, which is the number of time periods listed on the schedule. Next N lines, each line gives a time period, the format is:

hh:mm:ss - hh:mm:ss

Among them  hh, mm, ss are two-digit hours, minutes, and seconds respectively. The first time is the start time and the second is the end time. The question ensures that all times are within one day (that is, from 00:00:00 to 23:59:59); the interval between each interval is at least 1 second; and any two given time intervals overlap at most one endpoint. There is no overlap of intervals.

Output format:

List the intervals that do not appear in the timetable in chronological order, with each interval occupying one line and in the same format as the input. The question ensures that there is at least one interval that needs to be output.

Input example:

8
13:00:00 - 18:00:00
00:00:00 - 01:00:05
08:00:00 - 09:00:00
07:10:59 - 08:00:00
01:00:05 - 04:30:00
06:30:00 - 07:10:58
05:30:00 - 06:30:00
18:00:00 - 19:00:00

Output sample:

04:30:00 - 05:30:00
07:10:58 - 07:10:59
09:00:00 - 13:00:00
19:00:00 - 23:59:59

 Super simple

 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

int N;
vector<string>vv;

void solve(){
	N=vv.size();
	sort(vv.begin(),vv.end());//排个序
	
	string s0="00:00:00";//开始
	if(vv[0].find(s0)==-1)cout<<s0<<" - "<<vv[0].substr(0,8)<<endl;	
	
	for(int i=0; i<N-1;i++){//中间
		if(vv[i+1].find(vv[i].substr(11,19))!=-1)continue;
		else cout<<vv[i].substr(11,19)<<" - "<<vv[i+1].substr(0,8)<<endl;
	}
	
	s0="23:59:59";//最后
	if(vv[N-1].find(s0)==-1)cout<<vv[N-1].substr(11,19)<<" - "<<s0;
}	

int main(){
	cin>>N; 	getchar();	
	string s;
	while(N--){ 
		string s;
		getline(cin,s);
		vv.push_back(s); 
	}
	solve();       
    return 0;
}

 

 

 

 

 

Guess you like

Origin blog.csdn.net/QENGFENG/article/details/130178288