题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
没想到,有朝一日,俺单片机上学的控制数码管和键盘的表中查找法能用在这。
不过,俺不理解,这个if else的条件为什么反过来设就进不去else呢?
理解了,两个单目运算符不能连用,否则将分开两次执行。傻了傻了。
'A'<input[i]<'Z'相当于先判断'A'<input[i]是否为真,返回1,再判断1<'Z'是否为真。
这样永远为真,所以else永远进不去。
低级错误。
丢人。
#include<string.h>
char input[100];
int i=0,j=0,k=0,len;
char alpha_list[52]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char beta_list[52]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','7','7','7','8','8','8','9','9','9','9','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a'};
int main()
{
while(scanf("%s\n",&input)!= EOF)
{
len =strlen(input);//获取字符串长度
for(i=0;i<len;i++)
{
if((input[i]<'A')||(input[i]>'z'))
printf("%c",input[i]);
else
{
for(j=0;j<52;j++)
{
if(input[i]==alpha_list[j])
{
printf("%c",beta_list[j]);
}
}
}
}
}
}