c语言编程练习题:7-173 英文字母替换加密(大小写转换 后移1位)
作者:yunjinqi   类别:    日期:2023-05-31 18:33:17    阅读:454 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    char lower_alpha[27] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    char upper_alpha[27] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    char c;
    int index=0;
    while (scanf("%c",&c) && c!='\n'){
        if (c>='a' && c<='z'){
            for (int i=0;i<26;i++){
                if (lower_alpha[i]==c){
                    index=(i+1)%26;
                    printf("%c",upper_alpha[index]);
                    break;}
            }

        }else if (c>='A' && c<='Z'){
            for (int i=0;i<26;i++){
                if (upper_alpha[i]==c){
                    index=(i+1)%26;
                    printf("%c",lower_alpha[index]);
                    break;}
            }
        }else{
            printf("%c",c);
        }
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/298
上一篇:c语言编程练习题:7-172 简单求阶乘问题
下一篇:c语言编程练习题:7-174 字母串