题解 | #字符串加解密#

字符串加解密

http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

#include<stdio.h>
char enc(char a){
    if(a=='z')return 'A';
    if(a=='Z')return 'a';
    if(a=='9')return '0';
    if(a>='a'&&a<='z')return a+1-'a'+'A';
    if(a>='A'&&a<='Z')return a+1-'A'+'a';
    if(a>='0'&&a<='9')return a+1;
    return a;
}
char dec(char a){
    if(a=='a')return 'Z';
    if(a=='A')return 'z';
    if(a=='0')return '9';
    if(a>='a'&&a<='z')return a-1-'a'+'A';
    if(a>='A'&&a<='Z')return a-1-'A'+'a';
    if(a>='0'&&a<='9')return a-1;
    return a;
}
int main(){
    char s1[1001],s2[1001];
    while(~scanf("%s%s",s1,s2)){
        int i=0,j=0;
        while(s1[i]){
            s1[i]=enc(s1[i]);
            i++;
        }
        while(s2[j]){
            s2[j]=dec(s2[j]);
            j++;
        }
        printf("%s\n%s\n",s1,s2);
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务