题解 | #简单密码#

简单密码

http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

/*变换规则
(1)大写字母变成小写字母并向后移一位
(2)小写字母变成九键输入的对应数字
(3)数字和其他符号不变(密码中没有空格)
*/
#include <stdio.h>
#include <string.h>
int main(){
    char str[101];
    while(scanf("%s",str) != EOF){
        int len = strlen(str);
        for(int i = 0; i < len; i++){
            if(isupper(str[i])){  //大写字母
                if(str[i] == 'Z') str[i] = 'a';
                else str[i] = str[i] + 33;
            }
            else if(islower(str[i])){  //小写字母
                if(str[i] >= 'a' && str[i] <= 'c') str[i] = '2';
                else if(str[i] >= 'd' && str[i] <= 'f') str[i] = '3';
                else if(str[i] >= 'g' && str[i] <= 'i') str[i] = '4';
                else if(str[i] >= 'j' && str[i] <= 'l') str[i] = '5';
                else if(str[i] >= 'm' && str[i] <= 'o') str[i] = '6';
                else if(str[i] >= 'p' && str[i] <= 's') str[i] = '7';
                else if(str[i] >= 't' && str[i] <= 'v') str[i] = '8';
                else if(str[i] >= 'w' && str[i] <= 'z') str[i] = '9';
            }
        }
        puts(str);
    }
    return 0;
}
全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
notbeentak...:孩子,说实话,选择很重要,可能你换一个方向会好很多,但是现在时间不太够了,除非准备春招
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务