1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. class Clock{
  7.   int hour;
  8.   int minute;
  9.   int second;
  10.   int threshold;
  11. public:
  12.   Clock(int h, int m, int s, int t):hour(h),minute(m),second(s),threshold(t){};
  13.   Clock():hour(1),minute(12),second(720),threshold(0){};
  14.   bool checkSpace(){
  15.     if( spaceBetween(hour,minute) > (14400 + threshold))
  16.       return false;
  17.     if( spaceBetween(hour,minute) < (14400 - threshold))
  18.       return false;
  19.     if( spaceBetween(minute,second) > (14400 + threshold))
  20.       return false;
  21.     if( spaceBetween(minute,second) < (14400 - threshold))
  22.       return false;
  23.     if( spaceBetween(second,hour) > (14400 + threshold))
  24.       return false;
  25.     if( spaceBetween(second,hour) < (14400 - threshold))
  26.       return false;
  27.     return true;
  28.   }
  29.   void advance(){
  30.     hour += 1;
  31.     if(hour == 43200)
  32.       hour = 0;
  33.     minute += 12;
  34.     if(minute == 43200)
  35.       minute = 0;
  36.     second += 720;
  37.     if(second == 43200)
  38.       second = 0;
  39.   }
  40.   bool isNoon(){
  41.     if (hour == 0)
  42.       return true;
  43.     return false;
  44.   }
  45.   void print(){
  46.     cout << hour << ":" << minute << ":" << second << endl;
  47.     cout << "Which would read on a clock as: " << endl;
  48.     cout << hour / 3600 << ":" << minute / 720  << ":" << second / 720 << endl;
  49.     cout << "Threshold: " << threshold << endl;
  50.   }
  51.   void upThreshold(){
  52.     threshold++;
  53.   }
  54.   int spaceBetween(int one, int two){
  55.     if( (one - two) == 0)
  56.       return 0;
  57.     else if ( (one - two) > 0){
  58.       if ( (one - two) <= 21600)
  59.     return one - two;
  60.       else  
  61.     return 43200 - (one - two);
  62.     }
  63.     else if ( (one - two) < 0){
  64.       if ( (one - two) >= - 21600)
  65.     return abs(one - two);
  66.       else
  67.     return 43200 - abs(one - two);
  68.     }
  69.   }
  70. };
  71.  
  72. int main() {
  73.   Clock time;
  74.  
  75.   while(!time.checkSpace()){
  76.     if(time.isNoon())
  77.       time.upThreshold();
  78.     time.advance();
  79.   }
  80.  
  81.   time.print();
  82.   return 1;
  83. }
  84.