题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
/*************** *笨方法,可以采用数组列举对应关系查表法简便。 ***************/ #include <stdio.h> #include <string.h> int main() { char str[101]; char str1[101]; int len = 0, i, j; scanf( "%s", str ); len = strlen(str); for( i = 0; i<len; i++ ) { if( str[i] == 1 ) str1[i] = '1'; else if( str[i] == 'a' || str[i] == 'b' || str[i] == 'c' ) str1[i] = '2'; else if( str[i] == 'd' || str[i] == 'e' || str[i] == 'f' ) str1[i] = '3'; else if( str[i] == 'g' || str[i] == 'h' || str[i] == 'i' ) str1[i] = '4'; else if( str[i] == 'j' || str[i] == 'k' || str[i] == 'l' ) str1[i] = '5'; else if( str[i] == 'm' || str[i] == 'n' || str[i] == 'o' ) str1[i] = '6'; else if( str[i] == 'p' || str[i] == 'q' || str[i] == 'r' || str[i] == 's') str1[i] = '7'; else if( str[i] == 't' || str[i] == 'u' || str[i] == 'v' ) str1[i] = '8'; else if( str[i] == 'w' || str[i] == 'x' || str[i] == 'y'|| str[i] == 'z' ) str1[i] = '9'; else if( str[i] == '0' ) str1[i] = '0'; else if( str[i] >= 'A' && str[i] < 'Z' ) str1[i] = 'a' - 'A' + str[i] + 1; else if( str[i] == 'Z' ) str1[i] = 'a'; else str1[i] = str[i]; } for( i = 0; i<len; i++ ) printf( "%c", str1[i] ); return 0; }