#include <iostream> using namespace std; int main() { // 加密和解密 string plaintext; // 输入明文字符串 string ciphertext; // 输入密文字符串 cin >> plaintext >> ciphertext; // 输入明文和密文,以换行为标准 // 加密: // 然后按照字母顺序表向后移一位,同时转换大小写(是小写就转大写,大写就转小写) // 数字的话增加1,9转换为0 for (int i = 0; i < plaintext.length(); ++i) { if (plaintext[i] >= 'A' && plaintext[i] <= 'Z') { // 大写转小写 if (plaintext[i] == 'Z') { plaintext[i] = 'a'; } else { plaintext[i] += 33; } // plaintext[i] += 33; } else if (plaintext[i] >= 'a' && plaintext[i] <= 'z') { // 小写转大写 if (plaintext[i] == 'z') { plaintext[i] = 'A'; } else { plaintext[i] -= 31; } // plaintext[i] -= 31; } else if (plaintext[i] >= '0' && plaintext[i] <= '8') { plaintext[i] += 1; } else if (plaintext[i] == '9') { plaintext[i] = '0'; } } // 输出结果 cout << plaintext << endl; // 解密过程,与加密相反 for (int i = 0; i < ciphertext.length(); ++i) { if (ciphertext[i] >= 'A' && ciphertext[i] <= 'Z') { // 大写转小写 if (ciphertext[i] == 'A') { ciphertext[i] = 'z'; } else { ciphertext[i] += 31; } // ciphertext[i] += 31; } else if (ciphertext[i] >= 'a' && ciphertext[i] <= 'z') { // 小写转大写 if (ciphertext[i] == 'a') { ciphertext[i] = 'Z'; } else { ciphertext[i] -= 33; } // ciphertext[i] -= 33; } else if (ciphertext[i] >= '0' && ciphertext[i] <= '9') { if (ciphertext[i] == '0') { ciphertext[i] = '9'; } else { ciphertext[i] -= 1; } // ciphertext[i] -= 1; } } // 输出解密之后的结果 cout << ciphertext << endl; }