File Annotation
Not logged in
4fd800b3a8 2011-02-23        kinaba: #include <iostream>
4fd800b3a8 2011-02-23        kinaba: #include <sstream>
4fd800b3a8 2011-02-23        kinaba: #include <iomanip>
4fd800b3a8 2011-02-23        kinaba: #include <vector>
4fd800b3a8 2011-02-23        kinaba: #include <string>
4fd800b3a8 2011-02-23        kinaba: #include <map>
4fd800b3a8 2011-02-23        kinaba: #include <set>
4fd800b3a8 2011-02-23        kinaba: #include <algorithm>
4fd800b3a8 2011-02-23        kinaba: #include <numeric>
4fd800b3a8 2011-02-23        kinaba: #include <iterator>
4fd800b3a8 2011-02-23        kinaba: #include <complex>
4fd800b3a8 2011-02-23        kinaba: #include <queue>
4fd800b3a8 2011-02-23        kinaba: #include <stack>
4fd800b3a8 2011-02-23        kinaba: #include <cmath>
4fd800b3a8 2011-02-23        kinaba: #include <cassert>
4fd800b3a8 2011-02-23        kinaba: #include <cstring>
4fd800b3a8 2011-02-23        kinaba: using namespace std;
4fd800b3a8 2011-02-23        kinaba: typedef long long LL;
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: int to_i(const string& s) {
4fd800b3a8 2011-02-23        kinaba: 	int n;
4fd800b3a8 2011-02-23        kinaba: 	stringstream(s)>>n;
4fd800b3a8 2011-02-23        kinaba: 	return n;
4fd800b3a8 2011-02-23        kinaba: }
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: class BirthNumbersValidator {
4fd800b3a8 2011-02-23        kinaba: public:
4fd800b3a8 2011-02-23        kinaba: 	vector <string> validate(vector <string> test)
4fd800b3a8 2011-02-23        kinaba: 	{
4fd800b3a8 2011-02-23        kinaba: 		vector<string> ans;
4fd800b3a8 2011-02-23        kinaba: 		transform(test.begin(), test.end(), back_inserter(ans), &testeach);
4fd800b3a8 2011-02-23        kinaba: 		return ans;
4fd800b3a8 2011-02-23        kinaba: 	}
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: 	static string testeach( const string& x )
4fd800b3a8 2011-02-23        kinaba: 	{
4fd800b3a8 2011-02-23        kinaba: 		int y = to_i(x.substr(0,2));
4fd800b3a8 2011-02-23        kinaba: 		int m = to_i(x.substr(2,2));
4fd800b3a8 2011-02-23        kinaba: 		int d = to_i(x.substr(4,2));
4fd800b3a8 2011-02-23        kinaba: 		if( 1<=m && m<=12 ) {}
4fd800b3a8 2011-02-23        kinaba: 		else if( 51<=m && m<=62 ) { m-=50; }
4fd800b3a8 2011-02-23        kinaba: 		else return "NO";
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: 		bool leap = (y%4)==0;
4fd800b3a8 2011-02-23        kinaba: 		int dd[] = {31, leap?29:28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
4fd800b3a8 2011-02-23        kinaba: 		if( 1<=d && d<=dd[m-1] ) {}
4fd800b3a8 2011-02-23        kinaba: 		else return "NO";
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: 		LL cd; stringstream(x)>>cd;
4fd800b3a8 2011-02-23        kinaba: 		return cd%11==0 ? "YES" : "NO";
4fd800b3a8 2011-02-23        kinaba: 	}
4fd800b3a8 2011-02-23        kinaba: };
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: // BEGIN CUT HERE
4fd800b3a8 2011-02-23        kinaba: #include <ctime>
4fd800b3a8 2011-02-23        kinaba: double start_time;string timer() { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
4fd800b3a8 2011-02-23        kinaba: int verify_case(const vector <string> &Expected, const vector <string> &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } return 0;}
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: template<int N> struct Case_ { Case_(){start_time=clock();} };
4fd800b3a8 2011-02-23        kinaba: char Test_(...);
4fd800b3a8 2011-02-23        kinaba: int Test_(Case_<0>) {
4fd800b3a8 2011-02-23        kinaba: 	string test_[] = {"8104121234"};
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> test(test_, test_+sizeof(test_)/sizeof(*test_));
4fd800b3a8 2011-02-23        kinaba: 	string RetVal_[] = {"YES" };
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
4fd800b3a8 2011-02-23        kinaba: 	return verify_case(RetVal, BirthNumbersValidator().validate(test)); }
4fd800b3a8 2011-02-23        kinaba: int Test_(Case_<1>) {
4fd800b3a8 2011-02-23        kinaba: 	string test_[] = {"8154121239"};
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> test(test_, test_+sizeof(test_)/sizeof(*test_));
4fd800b3a8 2011-02-23        kinaba: 	string RetVal_[] = {"YES" };
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
4fd800b3a8 2011-02-23        kinaba: 	return verify_case(RetVal, BirthNumbersValidator().validate(test)); }
4fd800b3a8 2011-02-23        kinaba: int Test_(Case_<2>) {
4fd800b3a8 2011-02-23        kinaba: 	string test_[] = {"8134120005"};
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> test(test_, test_+sizeof(test_)/sizeof(*test_));
4fd800b3a8 2011-02-23        kinaba: 	string RetVal_[] = {"NO" };
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
4fd800b3a8 2011-02-23        kinaba: 	return verify_case(RetVal, BirthNumbersValidator().validate(test)); }
4fd800b3a8 2011-02-23        kinaba: int Test_(Case_<3>) {
4fd800b3a8 2011-02-23        kinaba: 	string test_[] = {"8102310007","8104121235"};
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> test(test_, test_+sizeof(test_)/sizeof(*test_));
4fd800b3a8 2011-02-23        kinaba: 	string RetVal_[] = {"NO", "NO" };
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
4fd800b3a8 2011-02-23        kinaba: 	return verify_case(RetVal, BirthNumbersValidator().validate(test)); }
4fd800b3a8 2011-02-23        kinaba: int Test_(Case_<4>) {
4fd800b3a8 2011-02-23        kinaba: 	string test_[] = {"0411131237"};
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> test(test_, test_+sizeof(test_)/sizeof(*test_));
4fd800b3a8 2011-02-23        kinaba: 	string RetVal_[] = {"YES" };
4fd800b3a8 2011-02-23        kinaba: 	  vector <string> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_));
4fd800b3a8 2011-02-23        kinaba: 	return verify_case(RetVal, BirthNumbersValidator().validate(test)); }
4fd800b3a8 2011-02-23        kinaba: 
4fd800b3a8 2011-02-23        kinaba: template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
4fd800b3a8 2011-02-23        kinaba: template<>      void Run_<-1>() {}
4fd800b3a8 2011-02-23        kinaba: int main() { Run_<0>(); }
4fd800b3a8 2011-02-23        kinaba: // END CUT HERE
4fd800b3a8 2011-02-23        kinaba: