Skip to content

Instantly share code, notes, and snippets.

@mcleary
Created May 25, 2016 02:35
Show Gist options
  • Save mcleary/df2114301a4ee3a3fce92c808f11bfe7 to your computer and use it in GitHub Desktop.
Save mcleary/df2114301a4ee3a3fce92c808f11bfe7 to your computer and use it in GitHub Desktop.
Meeting Schedules
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
void print_timespan(int start_time, int end_time)
{
if (start_time - 1 > 0) start_time--;
int start_hour = start_time / 60;
int start_minute = start_time - start_hour * 60;
int end_hour = end_time / 60;
int end_minute = end_time - end_hour * 60;
if (start_hour == 24) start_hour = 0;
if (end_hour == 24) end_hour = 0;
cout << setfill('0') << setw(2) << start_hour << " "
<< setfill('0') << setw(2) << start_minute << " "
<< setfill('0') << setw(2) << end_hour << " "
<< setfill('0') << setw(2) << end_minute
<< endl;
}
int main()
{
int number, meeting_timespan;
cin >> number >> meeting_timespan;
vector<bool> schedule(1440, true);
for (int i = 0; i < number; ++i)
{
int hour1, minutes1, hour2, minutes2;
cin >> hour1 >> minutes1 >> hour2 >> minutes2;
int start_time = hour1 * 60 + minutes1;
int end_time = hour2 * 60 + minutes2;
for (int i = start_time; i <= end_time; ++i)
{
schedule[i] = false;
}
}
int head = 0;
int tail = 0;
//cout << endl;
while (head < schedule.size())
{
tail = distance(schedule.begin(), find(schedule.begin() + head, schedule.end(), false));
int length = tail - head + 1;
if (length >= meeting_timespan)
{
print_timespan(head, tail);
}
head = distance(schedule.begin(), find(schedule.begin() + tail, schedule.end(), true));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment