Skip to content

Instantly share code, notes, and snippets.

@Shirataki2
Created November 24, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shirataki2/1e9e27fe759526cc0cee7fa9797290f7 to your computer and use it in GitHub Desktop.
Save Shirataki2/1e9e27fe759526cc0cee7fa9797290f7 to your computer and use it in GitHub Desktop.
#include "bits/stdc++.h"
using namespace std;
static const int inf = 1<<30;
int tl[24*13];
vector<int> split(const string &s, char delim) {
vector<int> elems;
string item;
for (char ch: s) {
if (ch == delim) {
if (!item.empty())
elems.push_back(atoi(item.c_str()));
item.clear();
}
else {
item += ch;
}
}
if (!item.empty())
elems.push_back(atoi(item.c_str()));
return elems;
}
int TLtoTime(int _tl){
int h=_tl/12;
int m=_tl%12;
return h*100+5*m;
}
int TimetoTL(int time,int md){
if(md==1) time+=(5-(time%5))==5? 0:(5-(time%5)); else time-=time%5;
int m = (time % 100)/5;
int h = time /100;
return h*12+m;
}
int main(void){
int N;
cin >> N;
vector<int> v;
for(int i=0;i<12*24+1;i++){
tl[i]=0;
}
for(int i=0;i<N;i++){
string str;
cin >> str;
v=split(str, '-');
int b=TimetoTL(v[0],0);
int e=TimetoTL(v[1],1);
tl[b]+=1;
tl[e]+=-1;
}
for(int i=0;i<12*24+1;i++){
if(i==0) continue;
tl[i]=tl[i]+tl[i-1];
}
bool check=false;
for(int i=0;i<12*24+1;i++){
if(tl[i]>=1 && !check){cout << setw(4) << setfill('0')<< TLtoTime(i)<<"-"; check=true;}
if(tl[i]==0 && check) {cout << setw(4) << setfill('0')<<TLtoTime(i)<<endl; check=false;}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment