Guest User

Untitled

a guest
Dec 9th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. ifstream ifs("input.txt");
  10. ofstream ofs("output.txt");
  11.  
  12. class time{
  13. private:
  14.     int h,m,s;
  15. public:
  16.     time():h(0),m(0),s(0){};
  17.     time(int a,int b,int c):h(a),m(b),s(c){};
  18.     time(string s):
  19.         h((s[0]-'0')*10+(s[1]-'0')),
  20.         m((s[3]-'0')*10+(s[4]-'0')),
  21.         s((s[6]-'0')*10+(s[7]-'0'))
  22.         {};
  23.     const time operator+(const int& sec) const {
  24.         time t(h,m,s);
  25.         t.s+=sec;
  26.         t.m+=t.s/60;
  27.         t.s=t.s%60;
  28.         t.h+=t.m/60;
  29.         t.m=t.m%60;
  30.         return t;
  31.     };
  32.     friend ostream& operator<<(ostream& os, const time& t){
  33.         if(t.h<10)os<<'0';
  34.         os<<t.h<<':';
  35.         if(t.m<10)os<<'0';
  36.         os<<t.m<<':';
  37.         if(t.s<10)os<<'0';
  38.         os<<t.s;
  39.         return os;
  40.     };
  41.     friend istream& operator>>(istream& is, time& t){
  42.         string s;
  43.         is>>s;
  44.         t=s;
  45.         return is;
  46.     };
  47.     const bool operator==(const time t)const{
  48.         return ((t.s+t.m*60+t.h*3600)==(s+m*60+h*3600))?1:0;
  49.     };
  50.     const bool operator!=(const time t)const{
  51.         return ((t.s+t.m*60+t.h*3600)==(s+m*60+h*3600))?0:1;
  52.     };
  53.     const bool operator>(const time t)const{
  54.         return ((t.s+t.m*60+t.h*3600)<(s+m*60+h*3600))?1:0;
  55.     };
  56.     const bool operator<(const time t)const{
  57.         return ((t.s+t.m*60+t.h*3600)<(s+m*60+h*3600))?0:1;
  58.     };
  59.     bool zero(){
  60.         if(h&&m&&s) return true;
  61.         return false;
  62.     };
  63.     void null(){
  64.         h=0;
  65.         m=0;
  66.         s=0;
  67.     };
  68. };
  69.  
  70. int check(int n,int t,int l,vector<time>& v){
  71.     for(int j=n+1;j<=l;j++)
  72.             if(v[n].zero()||v[j].zero())
  73.                 if((v[n]+t)==v[j]){
  74.                     ofs<<v[n]<<'-'<<v[j]<<endl;
  75.                     v[n].null();
  76.                     v[j].null();
  77.                     return 0;
  78.                 }
  79. };
  80.  
  81. int main()
  82. {
  83.     string s;
  84.     int n,t;
  85.     ifs>>n>>t;
  86.     n*=2;
  87.     vector<time>v(n);
  88.     for(int i=0;i<n;i++)ifs>>v[i];
  89.     sort(v.begin(),v.end());
  90.     for(int i=0;i<n-1;i++)check(i,t,n,v);
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment