-
POJ 1298-The Hardest Problem Ever(Caesar 密码)
-
题目链接:
The Hardest Problem Ever
-
思路:
题目大意:
对消息原文中的每个字母,分别用该字母之后的第5个字母替换(例如:消息原文中的每个字母A都分别替换成字母F),其他字符不 变,并且消息原文的所有字母都是大写的
给定翻译后的消息,求原始信息
题解:
注意一个坑就好了,一样是循环,比如X可以变成C,
-
代码:
#include<iostream>
#include<string>
using namespace std;
string Start = "START";
string End = "END";
string End_input = "ENDOFINPUT";
int main()
{
string Code_str;
while (getline(cin,Code_str))
{
if (Code_str == Start || Code_str == End) //跳过提示字符串
continue;
if (Code_str == End_input)
break;
int index=0;
while (index != Code_str.length())
{
if (Code_str[index] <= 'Z'&&Code_str[index] >= 'A')
{
if (Code_str[index] - 5 < 'A')
Code_str[index] = 'Z' - (4 - (Code_str[index] - 'A'));
else
Code_str[index] -= 5;
}
cout << Code_str[index];
index++;
}
cout << endl;
Code_str.clear();
}
return 0;
}
博客围绕POJ 1298 - The Hardest Problem Ever展开,涉及Caesar密码。题目要求对翻译后的消息求原始信息,规则是原文大写字母用其后第5个字母替换,其他字符不变。题解需注意循环情况,如X可变成C。
1430

被折叠的 条评论
为什么被折叠?



