e62379df86 2021-05-22 kinaba: #include <iostream> e62379df86 2021-05-22 kinaba: #include <sstream> e62379df86 2021-05-22 kinaba: #include <iomanip> e62379df86 2021-05-22 kinaba: #include <vector> e62379df86 2021-05-22 kinaba: #include <string> e62379df86 2021-05-22 kinaba: #include <map> e62379df86 2021-05-22 kinaba: #include <set> e62379df86 2021-05-22 kinaba: #include <algorithm> e62379df86 2021-05-22 kinaba: #include <numeric> e62379df86 2021-05-22 kinaba: #include <iterator> e62379df86 2021-05-22 kinaba: #include <functional> e62379df86 2021-05-22 kinaba: #include <complex> e62379df86 2021-05-22 kinaba: #include <queue> e62379df86 2021-05-22 kinaba: #include <stack> e62379df86 2021-05-22 kinaba: #include <cmath> e62379df86 2021-05-22 kinaba: #include <cassert> e62379df86 2021-05-22 kinaba: #include <tuple> e62379df86 2021-05-22 kinaba: using namespace std; e62379df86 2021-05-22 kinaba: typedef long long LL; e62379df86 2021-05-22 kinaba: typedef complex<double> CMP; e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: class RPSMagicTrick { public: e62379df86 2021-05-22 kinaba: string guess(string exampleGuess, string exampleResponse, string volunteersActions) e62379df86 2021-05-22 kinaba: { e62379df86 2021-05-22 kinaba: string W = string() + exampleGuess[0]; e62379df86 2021-05-22 kinaba: string L = string() + exampleGuess[1]; e62379df86 2021-05-22 kinaba: bool T = (exampleResponse[0] == 'R'); e62379df86 2021-05-22 kinaba: string ans; e62379df86 2021-05-22 kinaba: for (int i = 0; i < volunteersActions.size(); ++i) { e62379df86 2021-05-22 kinaba: if (volunteersActions[i] == '?') { e62379df86 2021-05-22 kinaba: ans += (T ? W + L : L + W); e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: else { e62379df86 2021-05-22 kinaba: T = !T; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: return ans; e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: }; e62379df86 2021-05-22 kinaba: e62379df86 2021-05-22 kinaba: // BEGIN CUT HERE e62379df86 2021-05-22 kinaba: #include <ctime> e62379df86 2021-05-22 kinaba: double start_time; string timer() e62379df86 2021-05-22 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e62379df86 2021-05-22 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e62379df86 2021-05-22 kinaba: { os << "{ "; e62379df86 2021-05-22 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e62379df86 2021-05-22 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e62379df86 2021-05-22 kinaba: void verify_case(const string& Expected, const string& Received) { e62379df86 2021-05-22 kinaba: bool ok = (Expected == Received); e62379df86 2021-05-22 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e62379df86 2021-05-22 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } e62379df86 2021-05-22 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e62379df86 2021-05-22 kinaba: #define END verify_case(_, RPSMagicTrick().guess(exampleGuess, exampleResponse, volunteersActions));} e62379df86 2021-05-22 kinaba: int main(){ e62379df86 2021-05-22 kinaba: CASE(0) e62379df86 2021-05-22 kinaba: string exampleGuess = "BA"; e62379df86 2021-05-22 kinaba: string exampleResponse = "Right."; e62379df86 2021-05-22 kinaba: string volunteersActions = "W?S??W??SS??WS?W??"; e62379df86 2021-05-22 kinaba: string _ = "ABBAACBCCAABABABBACB"; e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(1) e62379df86 2021-05-22 kinaba: string exampleGuess = "BA"; e62379df86 2021-05-22 kinaba: string exampleResponse = "Wrong."; e62379df86 2021-05-22 kinaba: string volunteersActions = "?S?WS?SW?WSWWS-???S??WWW?"; e62379df86 2021-05-22 kinaba: string _ = "ABCBCBBACBBACBCBABCA"; e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: /* e62379df86 2021-05-22 kinaba: CASE(2) e62379df86 2021-05-22 kinaba: string exampleGuess = ; e62379df86 2021-05-22 kinaba: string exampleResponse = ; e62379df86 2021-05-22 kinaba: string volunteersActions = ; e62379df86 2021-05-22 kinaba: string _ = ; e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: CASE(3) e62379df86 2021-05-22 kinaba: string exampleGuess = ; e62379df86 2021-05-22 kinaba: string exampleResponse = ; e62379df86 2021-05-22 kinaba: string volunteersActions = ; e62379df86 2021-05-22 kinaba: string _ = ; e62379df86 2021-05-22 kinaba: END e62379df86 2021-05-22 kinaba: */ e62379df86 2021-05-22 kinaba: } e62379df86 2021-05-22 kinaba: // END CUT HERE