再水一道题
#include <iostream> #include <cstring> // use strlen #include <string> using namespace std; const int Max = 1e2+50; int main() { char a[Max], b[Max], c[Max]; char key[Max] = {}, tkey[Max] = {}; int fl = 0, sum = 26; cin >> a >> b >> c; for (int i = 0; i < strlen(a); ++i) { if (key[a[i]-'A'] != '\0' && key[a[i]-'A'] != b[i]) { fl = 1; break; } else { if (tkey[b[i]-'A'] != '\0' && tkey[b[i]-'A'] != a[i]) { fl = 1; break; } if (tkey[b[i]-'A'] == '\0') --sum; key[a[i]-'A'] = b[i]; tkey[b[i]-'A'] = a[i]; } } if (sum) fl = 1; if (fl) cout << "Failed"; else for (int i = 0; i < strlen(c); ++i) cout << key[c[i]-'A']; return 0; }
语言c++计算机程序设计爱好者
不定期更新题目题解
望互相分享心得体会
有意留言加q