Artifact Content
Not logged in

Artifact 3c8f623356e9f51dba4433bcf44aecb33a48a29d


#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 TheTriangleBothDivs { public:
	string fix(string time) 
	{
		string answer;

		for(int hh= 0; hh<=23; ++hh)
		for(int mm= 0; mm<=59; ++mm)
		for(int of=-9; of<=+9; ++of)
			if( is_possible(hh,mm,of,time) ) {
				stringstream ss;
				ss << setw(2) << setfill('0') << (hh-of+24)%24
				   << ":"
				   << setw(2) << setfill('0') << mm;

				if( answer.empty() || ss.str()<answer )
					answer = ss.str();
			}
		return answer;
	}

	bool is_possible(int hh, int mm, int of, const string& time)
	{
		stringstream ss;
		ss << setw(2) << setfill('0') << hh
		   << ":"
		   << setw(2) << setfill('0') << mm
		   << " GMT"
		   << (of>=0 ? '+' : '-')
		   << (of>=0 ? of : -of);

		string s = ss.str();
		for(int i=0; i<s.size(); ++i)
			if( s[i] != time[i] && time[i]!='?' )
				return false;
		return true;
	}
};

// 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(_, TheTriangleBothDivs().fix(time));}
int main(){

CASE(0)
	string time = "17:45 GMT-4"; 
	string _ = "21:45"; 
END
CASE(1)
	string time = "16:?? GMT??"; 
	string _ = "00:00"; 
END
CASE(2)
	string time = "?1:34 GMT-9"; 
	string _ = "06:34"; 
END
CASE(3)
	string time = "??:?? GMT??"; 
	string _ = "00:00"; 
END
CASE(4)
	string time = "01:?? GMT?1"; 
	string _ = "00:00"; 
END
CASE(5)
	string time = "00:00 GMT-?"; 
	string _ = "01:00"; 
END

}
// END CUT HERE