Run ID:115783

提交时间:2025-04-04 16:58:24

#include <iostream> #include <string> #include <algorithm> // 用于 std::reverse using namespace std; string decrypt(const string& encrypted) { string decrypted = encrypted; // 1. 大小写反转 for (char& c : decrypted) { if (c >= 'a' && c <= 'z') { c = c - 'a' + 'A'; // 小写转大写 } else if (c >= 'A' && c <= 'Z') { c = c - 'A' + 'a'; // 大写转小写 } } // 2. 逆序存储 reverse(decrypted.begin(), decrypted.end()); // 3. 字符循环右移三个位置 for (char& c : decrypted) { if (c >= 'a' && c <= 'z') { c = (c - 'a' + 3) % 26 + 'a'; // 小写字母右移 } else if (c >= 'A' && c <= 'Z') { c = (c - 'A' + 3) % 26 + 'A'; // 大写字母右移 } } return decrypted; } int main() { string encrypted; cin >> encrypted; // 读取加密字符串 string decrypted = decrypt(encrypted); // 解密 cout << decrypted << endl; // 输出解密结果 return 0; }