题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include <stdio.h> #include <string.h> #define N 110 char s[N]; int main() { scanf("%[^\n]", s); for (int i = 0; i < strlen(s); i ++ ) { if (s[i] >= 'a' && s[i] <= 'z') { if (s[i] >= 'a' && s[i] <= 'c') s[i] = '2'; if (s[i] >= 'd' && s[i] <= 'f') s[i] = '3'; if (s[i] >= 'g' && s[i] <= 'i') s[i] = '4'; if (s[i] >= 'j' && s[i] <= 'l') s[i] = '5'; if (s[i] >= 'm' && s[i] <= 'o') s[i] = '6'; if (s[i] >= 'p' && s[i] <= 's') s[i] = '7'; if (s[i] >= 't' && s[i] <= 'v') s[i] = '8'; if (s[i] >= 'w' && s[i] <= 'z') s[i] = '9'; } if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = (s[i] - 'A' + 1) % 26 + 'a'; } } for (int i = 0; i < strlen(s); i ++ ) printf("%c", s[i]); return 0; }