原文中所有的字符都在字母表中被循环右移了三个位置( abz -> dec ) 逆序存储(abcd -> dcba ) 大小写反转(abXY -> ABxy) 输入 原文。(长度小于 5050 且只包含大小写字母) 输出 输出加密后的字符串。用C++语言编写
时间: 2024-04-08 16:33:26 浏览: 14
以下是使用C++语言编写的加密程序:
```cpp
#include <iostream>
#include <string>
#include <algorithm>
std::string encryptText(const std::string& text) {
std::string encryptedText = text;
// 循环右移三个位置
for (char& c : encryptedText) {
if (std::isalpha(c)) {
c = (c - 'a' + 3) % 26 + 'a';
}
}
// 逆序存储
std::reverse(encryptedText.begin(), encryptedText.end());
// 大小写反转
for (char& c : encryptedText) {
if (std::islower(c)) {
c = std::toupper(c);
} else if (std::isupper(c)) {
c = std::tolower(c);
}
}
return encryptedText;
}
int main() {
std::string originalText;
std::cout << "请输入原文: ";
std::getline(std::cin, originalText);
std::string encryptedText = encryptText(originalText);
std::cout << "加密后的字符串: " << encryptedText << std::endl;
return 0;
}
```
您可以将以上代码保存为一个.cpp文件,并使用C++编译器进行编译运行。输入原文后,程序将输出加密后的字符串。请注意,该程序仅适用于长度小于5050且只包含大小写字母的情况。