C程序-蓝桥-文本加密

问题描述

  先编写函数EncryptChar,按照下述规则将给定的字符c转化(加密)为新的字符:"A"转化"B","B"转化为"C",... ..."Z"转化为"a","a"转化为"b",... ..., "z"转化为"A",其它字符不加密。编写程序,加密给定字符串。

样例输出

与上面的样例输入对应的输出。
例:

数据规模和约定

  输入数据中每一个数的范围。
  例:50个字符以内无空格字符串。

#include <stdio.h>

int main( ) 
{
    char str[55];
    scanf("%s",str);//接收文本字符串 
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]>='A'&&str[i]<'Z') 
            str[i]=str[i]+1;//ACCII码加1,即可把A变成B 
        else if(str[i]=='Z')
            str[i]='a';
        else if(str[i]>='a'&&str[i]<'z')
            str[i]=str[i]+1;
        else if(str[i]=='z')
            str[i]='A';
    }
    
    printf("%s",str);
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40788199/article/details/84578714