解题思路:
根据输入建立译码表
检查2、3情况的发生
注意事项:
参考代码:
#include <iostream> // #include <sstream> // #include <cstdio> // #include <algorithm> // #include <cmath> // #include <cstdlib> #include <cstring> // #include <cctype> // #include <string> // #include <climits> // #include <map> // #include <vector> // #include <list> // #include <set> using namespace std; // const int maxn = 40004; // const long long MOD = 100000007; // const double PI = acos(-1.0); int main() { // input string origi, encry, r; cin >> origi >> encry >> r; // construct decode map char decode[26]; // 'A'->decode[0], 'B'->decode[1], ... memset( decode, 0, 26 * sizeof (char) ); bool is_failed = false; for (int i = 0; i < origi.size(); i++) { char *pch = &decode[ origi[ i ] - 'A' ]; if (*pch == 0) *pch = encry[ i ]; else if (*pch != encry[ i ]) { // situation 3 is_failed = true; break; } } if ( ! is_failed ) { // check situation 2 for (int i = 0; i < 26; i++) { if (decode[ i ] == 0) { is_failed = true; break; } } } // output if ( is_failed ) cout << "Failed" << endl; else { for (int i = 0; i < r.size(); i++) { cout << decode[ r[ i ] - 'A' ]; } cout << endl; } return 0; }
0.0分
2 人评分
求组合数 (C语言代码)浏览:1159 |
用筛法求之N内的素数。 (C语言代码)浏览:653 |
C语言考试练习题_保留字母 (C语言代码)浏览:713 |
sizeof的大作用 (C语言代码)浏览:1452 |
简单的a+b (C语言代码)浏览:419 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:646 |
C二级辅导-公约公倍 (C语言代码)浏览:483 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:324 |
C语言训练-大、小写问题 (C语言代码)浏览:682 |
龟兔赛跑预测 (C++代码)浏览:1183 |