题解 | #简单密码#

简单密码

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

#include <stdio.h>
#include <string.h>

//11.34-11.47 15分钟
int main() {
    char str[102] = {0};
    fgets(str, sizeof(str), stdin);
    str[strcspn(str, "\n")] = 0;
    str[strcspn(str, "\r")] = 0;

    int len = strlen(str);
    int i = 0;
    char offset = 'a' - 'A';
    for (i = 0; i < len ; i++) {
        //先大写变换
        if (str[i] >= 'A' && str[i] <= 'Y') {
            str[i] += offset+1;
        }
        else if (str[i] == 'Z') {
            str[i] = 'a';
        }
        else if (str[i] == 'a' || str[i] == 'b' || str[i] == 'c') {
            str[i] = '2';
        }
        else if (str[i] == 'd' || str[i] == 'e' || str[i] == 'f') {
            str[i] = '3';
        }
        else if (str[i] == 'g' || str[i] == 'h' || str[i] == 'i') {
            str[i] = '4';
        }
        else if (str[i] == 'j' || str[i] == 'k' || str[i] == 'l') {
            str[i] = '5';
        }
        else if (str[i] == 'm' || str[i] == 'n' || str[i] == 'o') {
            str[i] = '6';
        }
        else if (str[i] == 'p' || str[i] == 'q' || str[i] == 'r' || str[i] == 's') {
            str[i] = '7';
        }
        else if (str[i] == 't' || str[i] == 'u' || str[i] == 'v') {
            str[i] = '8';
        }
        else if (str[i] == 'w' || str[i] == 'x' || str[i] == 'y' || str[i] == 'z') {
            str[i] = '9';
        }
    }

    printf("%s", str);

    return 0;
}

樯橹灰飞烟灭

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-05 10:13
已编辑
HHHHaos:让这些老登来现在秋招一下,简历都过不去
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务