class ChessboardPattern { public: vector <string> makeChessboard(int h, int w) { vector <string> v; string s(w, '.'); string t(w, '.'); for(int i=0; i<w; ++i){ if(i % 2)s[i] = 'X'; else t[i] = 'X'; } int i = h % 2; while( v.size() < h ){ if(i)v.push_back( s ); else v.push_back( t ); i ^= 1; } return v; } };500
topcoderでまで日付の問題やりたくない。
bool isleap(int y) { if(y%4 == 0){ if(y%100 == 0 && y%400 != 0)return false; return true; } return false; } string check(string s) { const string Y = "YES"; const string N = "NO"; int mx[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int y = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[2] - '0') * 10 + (s[3] - '0'); int d = (s[4] - '0') * 10 + (s[5] - '0'); lli sum = 0; for(int i=0; i<s.size(); ++i){ sum = sum * 10 + (lli)(s[i] - '0'); } if( sum % 11 )return N; if( 51 <= m )m -= 50; if(m < 1 || 12 < m)return N; if( d == 0 )return N; if( mx[m-1] + (m == 2 && isleap(y)) < d )return N; return Y; } class BirthNumbersValidator { public: vector <string> validate(vector <string> test) { vector<string> v; for(int i=0; i<test.size(); ++i){ v.push_back( check(test[i]) ); } return v; } };1000
0 件のコメント :
コメントを投稿