4977026daf 2012-01-14 kinaba: #include <iostream> 4977026daf 2012-01-14 kinaba: #include <sstream> 4977026daf 2012-01-14 kinaba: #include <iomanip> 4977026daf 2012-01-14 kinaba: #include <vector> 4977026daf 2012-01-14 kinaba: #include <string> 4977026daf 2012-01-14 kinaba: #include <map> 4977026daf 2012-01-14 kinaba: #include <set> 4977026daf 2012-01-14 kinaba: #include <algorithm> 4977026daf 2012-01-14 kinaba: #include <numeric> 4977026daf 2012-01-14 kinaba: #include <iterator> 4977026daf 2012-01-14 kinaba: #include <functional> 4977026daf 2012-01-14 kinaba: #include <complex> 4977026daf 2012-01-14 kinaba: #include <queue> 4977026daf 2012-01-14 kinaba: #include <stack> 4977026daf 2012-01-14 kinaba: #include <cmath> 4977026daf 2012-01-14 kinaba: #include <cassert> 4977026daf 2012-01-14 kinaba: #include <cstring> 4977026daf 2012-01-14 kinaba: #ifdef __GNUC__ 4977026daf 2012-01-14 kinaba: #include <ext/hash_map> 4977026daf 2012-01-14 kinaba: #define unordered_map __gnu_cxx::hash_map 4977026daf 2012-01-14 kinaba: #else 4977026daf 2012-01-14 kinaba: #include <unordered_map> 4977026daf 2012-01-14 kinaba: #endif 4977026daf 2012-01-14 kinaba: using namespace std; 4977026daf 2012-01-14 kinaba: typedef long long LL; 4977026daf 2012-01-14 kinaba: typedef complex<double> CMP; 4977026daf 2012-01-14 kinaba: 4977026daf 2012-01-14 kinaba: class ThePalindrome { public: 4977026daf 2012-01-14 kinaba: int find(string s) 4977026daf 2012-01-14 kinaba: { 4977026daf 2012-01-14 kinaba: for(int i=0; i<s.size(); ++i) 4977026daf 2012-01-14 kinaba: if( is_palin(s + string(s.rbegin()+(s.size()-i), s.rend())) ) 4977026daf 2012-01-14 kinaba: return i + s.size(); 4977026daf 2012-01-14 kinaba: return s.size() * 2; 4977026daf 2012-01-14 kinaba: } 4977026daf 2012-01-14 kinaba: 4977026daf 2012-01-14 kinaba: bool is_palin(const string& s) { 4977026daf 2012-01-14 kinaba: return s == string(s.rbegin(), s.rend()); 4977026daf 2012-01-14 kinaba: } 4977026daf 2012-01-14 kinaba: }; 4977026daf 2012-01-14 kinaba: 4977026daf 2012-01-14 kinaba: // BEGIN CUT HERE 4977026daf 2012-01-14 kinaba: #include <ctime> 4977026daf 2012-01-14 kinaba: double start_time; string timer() 4977026daf 2012-01-14 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4977026daf 2012-01-14 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4977026daf 2012-01-14 kinaba: { os << "{ "; 4977026daf 2012-01-14 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4977026daf 2012-01-14 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4977026daf 2012-01-14 kinaba: void verify_case(const int& Expected, const int& Received) { 4977026daf 2012-01-14 kinaba: bool ok = (Expected == Received); 4977026daf 2012-01-14 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4977026daf 2012-01-14 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4977026daf 2012-01-14 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4977026daf 2012-01-14 kinaba: #define END verify_case(_, ThePalindrome().find(s));} 4977026daf 2012-01-14 kinaba: int main(){ 4977026daf 2012-01-14 kinaba: 4977026daf 2012-01-14 kinaba: CASE(0) 4977026daf 2012-01-14 kinaba: string s = "abab"; 4977026daf 2012-01-14 kinaba: int _ = 5; 4977026daf 2012-01-14 kinaba: END 4977026daf 2012-01-14 kinaba: CASE(1) 4977026daf 2012-01-14 kinaba: string s = "abacaba"; 4977026daf 2012-01-14 kinaba: int _ = 7; 4977026daf 2012-01-14 kinaba: END 4977026daf 2012-01-14 kinaba: CASE(2) 4977026daf 2012-01-14 kinaba: string s = "qwerty"; 4977026daf 2012-01-14 kinaba: int _ = 11; 4977026daf 2012-01-14 kinaba: END 4977026daf 2012-01-14 kinaba: CASE(3) 4977026daf 2012-01-14 kinaba: string s = "abdfhdyrbdbsdfghjkllkjhgfds"; 4977026daf 2012-01-14 kinaba: int _ = 38; 4977026daf 2012-01-14 kinaba: END 4977026daf 2012-01-14 kinaba: /* 4977026daf 2012-01-14 kinaba: CASE(4) 4977026daf 2012-01-14 kinaba: string s = ; 4977026daf 2012-01-14 kinaba: int _ = ; 4977026daf 2012-01-14 kinaba: END 4977026daf 2012-01-14 kinaba: CASE(5) 4977026daf 2012-01-14 kinaba: string s = ; 4977026daf 2012-01-14 kinaba: int _ = ; 4977026daf 2012-01-14 kinaba: END 4977026daf 2012-01-14 kinaba: */ 4977026daf 2012-01-14 kinaba: } 4977026daf 2012-01-14 kinaba: // END CUT HERE