Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- ifstream ifs("input.txt");
- ofstream ofs("output.txt");
- class time{
- private:
- int h,m,s;
- public:
- time():h(0),m(0),s(0){};
- time(int a,int b,int c):h(a),m(b),s(c){};
- time(string s):
- h((s[0]-'0')*10+(s[1]-'0')),
- m((s[3]-'0')*10+(s[4]-'0')),
- s((s[6]-'0')*10+(s[7]-'0'))
- {};
- const time operator+(const int& sec) const {
- time t(h,m,s);
- t.s+=sec;
- t.m+=t.s/60;
- t.s=t.s%60;
- t.h+=t.m/60;
- t.m=t.m%60;
- return t;
- };
- friend ostream& operator<<(ostream& os, const time& t){
- if(t.h<10)os<<'0';
- os<<t.h<<':';
- if(t.m<10)os<<'0';
- os<<t.m<<':';
- if(t.s<10)os<<'0';
- os<<t.s;
- return os;
- };
- friend istream& operator>>(istream& is, time& t){
- string s;
- is>>s;
- t=s;
- return is;
- };
- const bool operator==(const time t)const{
- return ((t.s+t.m*60+t.h*3600)==(s+m*60+h*3600))?1:0;
- };
- const bool operator!=(const time t)const{
- return ((t.s+t.m*60+t.h*3600)==(s+m*60+h*3600))?0:1;
- };
- const bool operator>(const time t)const{
- return ((t.s+t.m*60+t.h*3600)<(s+m*60+h*3600))?1:0;
- };
- const bool operator<(const time t)const{
- return ((t.s+t.m*60+t.h*3600)<(s+m*60+h*3600))?0:1;
- };
- bool zero(){
- if(h&&m&&s) return true;
- return false;
- };
- void null(){
- h=0;
- m=0;
- s=0;
- };
- };
- int check(int n,int t,int l,vector<time>& v){
- for(int j=n+1;j<=l;j++)
- if(v[n].zero()||v[j].zero())
- if((v[n]+t)==v[j]){
- ofs<<v[n]<<'-'<<v[j]<<endl;
- v[n].null();
- v[j].null();
- return 0;
- }
- };
- int main()
- {
- string s;
- int n,t;
- ifs>>n>>t;
- n*=2;
- vector<time>v(n);
- for(int i=0;i<n;i++)ifs>>v[i];
- sort(v.begin(),v.end());
- for(int i=0;i<n-1;i++)check(i,t,n,v);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment