B - AtCoderトランプ / AtCoderBeginnerContest #003
#include <iostream> #include <string> using namespace std; bool Check(string s, string t, int pos, int kind) { const char atcoder[7]={'a', 't', 'c', 'o', 'd', 'e', 'r'}; for (int i=0; i<7; ++i) { if (!kind && t[pos]==atcoder[i]) s[pos]=atcoder[i]; if (kind && s[pos]==atcoder[i]) t[pos]=atcoder[i]; } return (s[pos]==t[pos]? true :false); } void Solve(string s, string t) { bool flg=true; for (int i=0; i<s.length(); ++i) { if (!flg) break; if (s[i] != t[i]) { if (s[i]=='@' && t[i]=='@') continue; else if (s[i] == '@') flg=Check(s,t,i,0); else if (t[i] == '@') flg=Check(s,t,i,1); else { flg=false; break; } } } cout << (flg? "You can win" : "You will lose") << endl; } int main(void) { string s, t; cin >> s >> t; Solve(s,t); return 0; }
どちらの@か場合分けを行い、@を置き換えた時に文字が合致しているかを判別。
途中で文字が一致しなかった場合はYou will lose、全て一致した場合はYou can winを出力。
~了~