code4sk/c/sourcecode/朱森森带领的奇妙冒险/字符串1/英文字母替换加密(大小写转换+后移1位).cpp
2023-10-18 16:17:32 +08:00

45 lines
1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//英文字母替换加密(大小写转换+后移1位
//本题要求编写程序将英文字母替换加密。为了防止信息被别人轻易窃取需要把电码明文通过加密方式变换成为密文。变换规则是将明文中的所有英文字母替换为字母表中的后一个字母同时将小写字母转换为大写字母大写字母转换为小写字母。例如字母a->B、b->C、…、z->A、A->b、B->c、…、Z->a。输入一行字符将其中的英文字母按照以上规则转换后输出其他字符按原样输出。
//输入格式:
//输入一行字符,以回车符 '\n'作为 结束符。
//输出格式:
//将输入的一行字符中的所有英文字母替换为字母表中的后一个字母,同时将小写字母转换为大写字母,大写字母转换为小写字母后输出,其他字符按原样输出。
//输入样例:
//在这里给出一组输入。例如:
//Reold Z123?
//输出样例:
//在这里给出相应的输出。例如:
//sFPME a123?
#include <stdio.h>
int main()
{
char c;
while((c=getchar())!='\n')
{
if(c>='a'&&c<='y')
{
c=c-31;
printf("%c",c);
}
else if(c=='z')
printf("A");
else if(c>='A'&&c<='Y')
{
c=c+33;
printf("%c",c);
}
else if(c=='Z')
printf("a");
else
{
printf("%c",c);
}
}
}