密码翻译
题目背景
Update on 2023.01.21 11:33:00
\text{Update on 2023.01.21 11:33:00}
Update on 2023.01.21 11:33:00:目前数据已经修复,对于题解中提到的 @
应视作 A
的问题经调查发现为一个错误,现在已经修复。
题目描述
在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密。我们给出一种最简单的加密方法,对给定的一个字符串,把其中从 a ∼ y \texttt{a} \sim \texttt{y} a∼y, A ∼ Y \texttt{A} \sim \texttt{Y} A∼Y 的字母用其后继字母替代,把 z \texttt{z} z 和 Z \texttt{Z} Z 用 a \texttt{a} a 和 A \texttt{A} A 替代,其他非字母字符不变。请根据该加密规则将输入的密码进行解密。
提示:这里需要进行解密操作,而不是加密。
输入格式
一行,加密后的字符串,长度不多于 10000 10000 10000 个字符。
输出格式
一行,将密码解密后的字符串。
样例 #1
样例输入 #1
Ifmmp ! Ipx bsf zpv!
样例输出 #1
Hello ! How are you!
提示
感谢 @Hughpig 提供本题数据。
参考如下
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
int main()
{
char str[100001]={};
int i=0;
fgets(str, sizeof(str), stdin);
while(i<strlen(str))
{
if(isalpha(str[i]))
{
str[i]--;
if(str[i]=='A'-1||str[i]=='a'-1)
str[i]+=26;
}
i++;
}
printf("%s\n",str);
return 0;
}