ba35b3a9cf 2011-06-25 kinaba: #include <iostream> ba35b3a9cf 2011-06-25 kinaba: #include <sstream> ba35b3a9cf 2011-06-25 kinaba: #include <iomanip> ba35b3a9cf 2011-06-25 kinaba: #include <vector> ba35b3a9cf 2011-06-25 kinaba: #include <string> ba35b3a9cf 2011-06-25 kinaba: #include <map> ba35b3a9cf 2011-06-25 kinaba: #include <set> ba35b3a9cf 2011-06-25 kinaba: #include <algorithm> ba35b3a9cf 2011-06-25 kinaba: #include <numeric> ba35b3a9cf 2011-06-25 kinaba: #include <iterator> ba35b3a9cf 2011-06-25 kinaba: #include <functional> ba35b3a9cf 2011-06-25 kinaba: #include <complex> ba35b3a9cf 2011-06-25 kinaba: #include <queue> ba35b3a9cf 2011-06-25 kinaba: #include <stack> ba35b3a9cf 2011-06-25 kinaba: #include <cmath> ba35b3a9cf 2011-06-25 kinaba: #include <cassert> ba35b3a9cf 2011-06-25 kinaba: #include <cstring> ba35b3a9cf 2011-06-25 kinaba: using namespace std; ba35b3a9cf 2011-06-25 kinaba: typedef long long LL; ba35b3a9cf 2011-06-25 kinaba: typedef complex<double> CMP; ba35b3a9cf 2011-06-25 kinaba: ba35b3a9cf 2011-06-25 kinaba: class TripleStrings { public: ba35b3a9cf 2011-06-25 kinaba: int getMinimumOperations(string init, string goal) ba35b3a9cf 2011-06-25 kinaba: { ba35b3a9cf 2011-06-25 kinaba: for(int i=0; i<=init.size(); ++i) ba35b3a9cf 2011-06-25 kinaba: if( init.substr(i, init.size()-i) == goal.substr(0, init.size()-i) ) ba35b3a9cf 2011-06-25 kinaba: return 2*i; ba35b3a9cf 2011-06-25 kinaba: assert(false); ba35b3a9cf 2011-06-25 kinaba: return -1; ba35b3a9cf 2011-06-25 kinaba: } ba35b3a9cf 2011-06-25 kinaba: }; ba35b3a9cf 2011-06-25 kinaba: ba35b3a9cf 2011-06-25 kinaba: // BEGIN CUT HERE ba35b3a9cf 2011-06-25 kinaba: #include <ctime> ba35b3a9cf 2011-06-25 kinaba: double start_time; string timer() ba35b3a9cf 2011-06-25 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } ba35b3a9cf 2011-06-25 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) ba35b3a9cf 2011-06-25 kinaba: { os << "{ "; ba35b3a9cf 2011-06-25 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) ba35b3a9cf 2011-06-25 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } ba35b3a9cf 2011-06-25 kinaba: void verify_case(const int& Expected, const int& Received) { ba35b3a9cf 2011-06-25 kinaba: bool ok = (Expected == Received); ba35b3a9cf 2011-06-25 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; ba35b3a9cf 2011-06-25 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } ba35b3a9cf 2011-06-25 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); ba35b3a9cf 2011-06-25 kinaba: #define END verify_case(_, TripleStrings().getMinimumOperations(init, goal));} ba35b3a9cf 2011-06-25 kinaba: int main(){ ba35b3a9cf 2011-06-25 kinaba: ba35b3a9cf 2011-06-25 kinaba: CASE(0) ba35b3a9cf 2011-06-25 kinaba: string init = "ooxxox"; ba35b3a9cf 2011-06-25 kinaba: string goal = "xoxoxo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 6; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(1) ba35b3a9cf 2011-06-25 kinaba: string init = "oooxxoo"; ba35b3a9cf 2011-06-25 kinaba: string goal = "oooxxoo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 0; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(2) ba35b3a9cf 2011-06-25 kinaba: string init = "ox"; ba35b3a9cf 2011-06-25 kinaba: string goal = "xo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 2; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(3) ba35b3a9cf 2011-06-25 kinaba: string init = "ooxxooxx"; ba35b3a9cf 2011-06-25 kinaba: string goal = "xxoxoxoo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 12; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(4) ba35b3a9cf 2011-06-25 kinaba: string init = "oxxoxxoooxooooxxxoo"; ba35b3a9cf 2011-06-25 kinaba: string goal = "oxooooxxxooooxoxxxo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 16; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(5) ba35b3a9cf 2011-06-25 kinaba: string init = "xxxoxoxxooxooxoxooo"; ba35b3a9cf 2011-06-25 kinaba: string goal = "oxxooxxooxxoxoxooxo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 36; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(6) ba35b3a9cf 2011-06-25 kinaba: string init = "oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox"; ba35b3a9cf 2011-06-25 kinaba: string goal = "oooooooooooooooooooooooooxxxxxxxxxxxxxxxxxxxxxxxxx"; ba35b3a9cf 2011-06-25 kinaba: int _ = -1; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(7) ba35b3a9cf 2011-06-25 kinaba: string init = "o"; ba35b3a9cf 2011-06-25 kinaba: string goal = "o"; ba35b3a9cf 2011-06-25 kinaba: int _ = 0; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: CASE(8) ba35b3a9cf 2011-06-25 kinaba: string init = "ox"; ba35b3a9cf 2011-06-25 kinaba: string goal = "xo"; ba35b3a9cf 2011-06-25 kinaba: int _ = 2; ba35b3a9cf 2011-06-25 kinaba: END ba35b3a9cf 2011-06-25 kinaba: ba35b3a9cf 2011-06-25 kinaba: } ba35b3a9cf 2011-06-25 kinaba: // END CUT HERE