c语言编程练习题:7-190 凯撒密码
作者:yunjinqi   类别:    日期:2023-06-04 18:55:16    阅读:458 次   消耗积分:0 分    

image.png

#include <stdio.h>
#include <string.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;
    char arr[80];
    int offset=0;
    int count=0;
    int index=0;
    while (scanf("%c",&c)!=EOF && c!='\n'){
        arr[count]=c;
        count++;
    }
    if (scanf("%d",&offset)!=EOF){
        //printf("%d\n",offset);
    }
    for (int i=0;i<count;i++){
        c = arr[i];
        if (c>='a' && c<='z'){
            for (int j=0;j<26;j++){
                if (lower_alpha[j]==c){
                    index=(j+offset)%26;
                    while (index<0){
                        index+=26;
                    }
                    printf("%c",lower_alpha[index]);}
            }
        }else if (c>='A' && c<='Z'){
            for (int j=0;j<26;j++){
                if (upper_alpha[j]==c){
                    index=(j+offset)%26;
                    while (index<0){
                        index+=26;
                    }
                    printf("%c",upper_alpha[index]);}
            }
        }else{
            printf("%c",c);
        }

    }
    printf("\n");
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/314
上一篇:c语言编程练习题:7-189 西安距离
下一篇:c语言编程练习题:7-191 吉老师的回归