Artifact Content
Not logged in

Artifact 27159b7b45b871980139a67657fefab708e70914


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class RotatedClock { public:
	string getEarliest(int hourHand, int minuteHand)
	{
		for(int h=0; h<12; ++h)
			for(int m=0; m<60; ++m)
				for(int offset=0; offset<360; offset+=30) {
					int hx = (hourHand + offset) % 360;
					int mx = (minuteHand + offset) % 360;
					if( match(h, m, hx, mx) ) {
						char buf[100];
						sprintf(buf, "%02d:%02d", h, m);
						return buf;
					}
				}
		return string();
	}

	bool match(int h, int m, int hx, int mx)
	{
		return (h*60+m)*360 == hx*(12*60)
			&& m*360 == mx*60;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, RotatedClock().getEarliest(hourHand, minuteHand));}
int main(){

CASE(0)
	int hourHand = 70; 
	int minuteHand = 300; 
	string _ = "08:20"; 
END
CASE(1)
	int hourHand = 90; 
	int minuteHand = 120; 
	string _ = "11:00"; 
END
CASE(2)
	int hourHand = 240; 
	int minuteHand = 36; 
	string _ = ""; 
END
CASE(3)
	int hourHand = 19; 
	int minuteHand = 19; 
	string _ = ""; 
END
CASE(4)
	int hourHand = 1; 
	int minuteHand = 12; 
	string _ = "00:02"; 
END
/*
CASE(5)
	int hourHand = ; 
	int minuteHand = ; 
	string _ = ; 
END
CASE(6)
	int hourHand = ; 
	int minuteHand = ; 
	string _ = ; 
END
*/
}
// END CUT HERE