#include <stdio.h>
#include <string.h>
int main() {
int i,j;
char str[100];
scanf("%s", str);
j=strlen(str);
for(i=0;i<=j;i++)
{
if(str[i]>='A'&&str[i]<='Z')
{
if(str[i]=='Z')
str[i]='a';
else
str[i]=str[i]+33;
continue;
}
else if(str[i]>='a'&&str[i]<='z')
{
switch ( str[i]) {
case 'a':str[i]='2';break;
case 'b':str[i]='2';break;
case 'c':str[i]='2';break;
case 'd':str[i]='3';break;
case 'e':str[i]='3';break;
case 'f':str[i]='3';break;
case 'g':str[i]='4';break;
case 'h':str[i]='4';break;
case 'i':str[i]='4';break;
case 'j':str[i]='5';break;
case 'k':str[i]='5';break;
case 'l':str[i]='5';break;
case 'm':str[i]='6';break;
case 'n':str[i]='6';break;
case 'o':str[i]='6';break;
case 'p':str[i]='7';break;
case 'q':str[i]='7';break;
case 'r':str[i]='7';break;
case 's':str[i]='7';break;
case 't':str[i]='8';break;
case 'u':str[i]='8';break;
case 'v':str[i]='8';break;
case 'w':str[i]='9';break;
case 'x':str[i]='9';break;
case 'y':str[i]='9';break;
case 'z':str[i]='9';break;
default:break;
}
continue;
}
else continue;
}
printf("%s",str);
}
将得到的一串由大小写字母与数字组成的密码经过一定的处理之后输出到屏幕,首先确定字符串长度,然后利用循
环逐步判断每个字符的类型再进行处理,如果是数字则直接输出,注意特殊情况,当输入的是大写字母Z时。注意
ASCII码中字符与十进制数的对应关系。