题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include <stdio.h> #include <string.h> #define MAX 102 void transform(char *c){ if((*c >= 65) && (*c < 90)){ *c = (*c) + 33; } else if(*c == 90) *c = 97; } void transform_char_num(char *c){ if((*c >= 97) && (*c <= 122)){ if((*c >= 97) && (*c<= 99)) *c = '2'; else if((*c >= 100) && (*c<= 102)) *c = '3'; else if((*c >= 103) && (*c<= 105)) *c = '4'; else if((*c >= 106) && (*c<= 108)) *c = '5'; else if((*c >= 109) && (*c<= 111)) *c = '6'; else if((*c >= 112) && (*c<= 115)) *c = '7'; else if((*c >= 116) && (*c<= 118)) *c = '8'; else if((*c >= 119) && (*c<= 122)) *c = '9'; } } int main(){ char arr[MAX] = {0}; fgets(arr, sizeof(arr), stdin); arr[strlen(arr)] = '\0'; int len = strlen(arr); for(int i = 0; i < len; i++){ transform_char_num(&arr[i]); transform(&arr[i]); printf("%c", arr[i]); } //printf("%.*s", len, arr); return 0; }