题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include <stdio.h> int isNum(char ch) { if(ch >= '0' && ch <= '9') return 1; return 0; } int isBigAlpha(char ch) { if(ch >= 'A' && ch <= 'Z') return 1; return 0; } int isSmallAlpha(char ch) { if(ch >= 'a' && ch <= 'z') return 1; return 0; } char changeBigAlpha(char ch) { ch = ch - 'A' + 'a' + 1; if(ch == 'z' + 1) ch = 'a'; return ch; } char getSmallAlpha(char ch) { switch(ch) { case 'a': case 'b': case 'c': return '2'; case 'd': case 'e': case 'f': return '3'; case 'g': case 'h': case 'i':return '4'; case 'j': case 'k': case 'l':return '5'; case 'm': case 'n': case 'o':return '6'; case 'p': case 'q': case 'r': case 's':return '7'; case 't': case 'u': case 'v':return '8'; case 'w': case 'x': case 'y': case 'z':return '9'; } return 0; } int main() { char ch; char c; while(EOF != (ch = getchar())) { if(isBigAlpha(ch)) c = changeBigAlpha(ch); else if(isSmallAlpha(ch)) c = getSmallAlpha(ch); else c = ch; printf("%c",c); } return 0; }