题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
根据描述敲代码就可以了,没什么难度。
#include"stdio.h" #include"string.h" char str_1[1001] = { 0 }; char str_2[1001] = { 0 }; int main(void) { int len, i; scanf("%s", str_1); scanf("%s", str_2); len = strlen(str_1); for (i = 0; i < len; i++) { if (str_1[i] >= 'A' && str_1[i] < 'Z') { str_1[i] = str_1[i] + ('a' - 'A') + 1; } else if (str_1[i] == 'Z') { str_1[i] = 'a'; } else if (str_1[i] >= 'a' && str_1[i] < 'z') { str_1[i] = str_1[i] - ('a' - 'A') + 1; } else if (str_1[i] == 'z') { str_1[i] = 'A'; } else if (str_1[i] >= '0' && str_1[i] < '9') { str_1[i] = str_1[i] + 1; } else if (str_1[i] == '9') { str_1[i] = '0'; } } printf("%s\n", str_1); len = strlen(str_2); for (i = 0; i < len; i++) { if (str_2[i] > 'A' && str_2[i] <= 'Z') { str_2[i] = str_2[i] + ('a' - 'A') - 1; } else if (str_2[i] == 'A') { str_2[i] = 'z'; } else if (str_2[i] > 'a' && str_2[i] <= 'z') { str_2[i] = str_2[i] - ('a' - 'A') - 1; } else if (str_2[i] == 'a') { str_2[i] = 'Z'; } else if (str_2[i] > '0' && str_2[i] <= '9') { str_2[i] = str_2[i] - 1; } else if (str_2[i] == '0') { str_2[i] = '9'; } } printf("%s", str_2); return 0; }