题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <stdio.h> #include <string.h> int main() { char str[1001]; gets(str); char strE[1001]; gets(strE); int len = strlen(str); int lenE =strlen(strE); for(int i=0;i<len;i++) { if(str[i]>='a'&&str[i]<'z') str[i] = str[i] - 31; else if(str[i]=='z') str[i] = 'A'; else if(str[i]>='0'&&str[i]<'9') str[i]++; else if(str[i]=='9') str[i]='0'; else if(str[i]>='A'&&str[i]<'Z') str[i]=str[i] + 33; else if(str[i]=='Z') str[i]='a'; } for(int i=0;i<lenE;i++) { if(strE[i]>='b'&&strE[i]<='z') strE[i] = strE[i] - 1 - 32; else if(strE[i]=='a') strE[i] = 'Z'; else if(strE[i]>='1'&&strE[i]<='9') strE[i]--; else if(strE[i]=='0') strE[i]='9'; else if(strE[i]>='B'&&strE[i]<='Z') strE[i]=strE[i] + 32 -1; else if(strE[i]=='A') strE[i]='z'; } printf("%s\n",str); printf("%s\n",strE); return 0; }