#include #include using namespace std; class Clock{ int hour; int minute; int second; int threshold; public: Clock(int h, int m, int s, int t):hour(h),minute(m),second(s),threshold(t){}; Clock():hour(1),minute(12),second(720),threshold(0){}; bool checkSpace(){ if( spaceBetween(hour,minute) > (14400 + threshold)) return false; if( spaceBetween(hour,minute) < (14400 - threshold)) return false; if( spaceBetween(minute,second) > (14400 + threshold)) return false; if( spaceBetween(minute,second) < (14400 - threshold)) return false; if( spaceBetween(second,hour) > (14400 + threshold)) return false; if( spaceBetween(second,hour) < (14400 - threshold)) return false; return true; } void advance(){ hour += 1; if(hour == 43200) hour = 0; minute += 12; if(minute == 43200) minute = 0; second += 720; if(second == 43200) second = 0; } bool isNoon(){ if (hour == 0) return true; return false; } void print(){ cout << hour << ":" << minute << ":" << second << endl; cout << "Which would read on a clock as: " << endl; cout << hour / 3600 << ":" << minute / 720 << ":" << second / 720 << endl; cout << "Threshold: " << threshold << endl; } void upThreshold(){ threshold++; } int spaceBetween(int one, int two){ if( (one - two) == 0) return 0; else if ( (one - two) > 0){ if ( (one - two) <= 21600) return one - two; else return 43200 - (one - two); } else if ( (one - two) < 0){ if ( (one - two) >= - 21600) return abs(one - two); else return 43200 - abs(one - two); } } }; int main() { Clock time; while(!time.checkSpace()){ if(time.isNoon()) time.upThreshold(); time.advance(); } time.print(); return 1; }