题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include<stdio.h> #include<string.h> //argc是命令行总的参数个数; //argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数。命令行后面跟的用户输入的参数。 int main(int argc, char const *argv[]) { char strpwd[100]; char a[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; //非必要的参照字典 char b[] = {"bcdefghijklmnopqrstuvwxyza"}; //字符输出对应字典 int len = 0; while ( scanf("%s", strpwd) != EOF ) { len = strlen(strpwd); //大写字母与小写字母的交换 for (int i = 0; i < len; i++) { if (strpwd[i] >= 'A' && strpwd[i] <= 'Z') { for (int j = 0; j < 26; j++) { if (strpwd[i] == a[j]) { printf("%c", b[j]); strpwd[i] = b[j]; } } continue; } //小写字母与数字的对换 if (strpwd[i] >= 'a' && strpwd[i] <= 'c') { strpwd[i]='2'; }else if (strpwd[i] >= 'd' && strpwd[i] <= 'f') { strpwd[i]='3'; }else if (strpwd[i] >= 'g' && strpwd[i] <= 'i') { strpwd[i]='4'; }else if (strpwd[i] >= 'j' && strpwd[i] <= 'l') { strpwd[i]='5'; }else if (strpwd[i] >= 'm' && strpwd[i] <= 'o') { strpwd[i]='6'; }else if (strpwd[i] >= 'p' && strpwd[i] <= 's') { strpwd[i]='7'; }else if (strpwd[i] >= 't' && strpwd[i] <= 'v') { strpwd[i]='8'; }else if (strpwd[i] >= 'w' && strpwd[i] <= 'z') { strpwd[i]='9'; } printf("%c", strpwd[i]); } // printf("%s\n", strpwd); 不知道为啥大写转小写的输出Char输出就不对,只输出数字。求大神解释。 // puts(strpwd); } return 0; }