题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <stdio.h> char getEnChar(char ch) { char ret = 0; if(ch >= 'a' && ch <= 'z') { ret = (ch + 1 - 'a') % 26 + 'A'; } else if(ch >= 'A' && ch <= 'Z') { ret = (ch + 1 - 'A') % 26 + 'a'; } else if(ch >= '0' && ch <= '9') { ret = (ch + 1 - '0') % 10 + '0'; } return ret; } char getDeChar(char ch) { char ret = 0; if(ch >= 'a' && ch <= 'z') { ret = (ch + 25 - 'a') % 26 + 'A'; } else if(ch >= 'A' && ch <= 'Z') { ret = (ch + 25 - 'A') % 26 + 'a'; } else if(ch >= '0' && ch <= '9') { ret = (ch + 9 - '0') % 10 + '0'; } return ret; } int main() { char ch = 0; char flag = 0; while(EOF != (ch = getchar())) { if(ch == '\n') { flag = 1; printf("\n"); continue; }else{ if(0 == flag) { printf("%c",getEnChar(ch)); }else if(1 == flag) { printf("%c",getDeChar(ch)); } } } return 0; }