题解 | #简单密码#

简单密码

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

按照题目要求一步步的实现
/**
 * @file hj21-简单密码.cc
 * @author (malixian)
 * @brief 大写变小写,然后后移一位;小写变数字;数字不变
 * @version 0.1
 * @date 2022-08-11
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include <iostream>
#include <string>

using namespace std;

void mima()
{
    string str;
    getline(cin, str);

    for (auto &c : str) {
        if (isupper(c)) {   // 大写转小写,小写后移动一位
            c = tolower(c);
            if (c != 'z') {
                c = c + 1;
            } else {
                c = 'a';
            }
            continue;
        // 小写转数字
        } else if ('a' <= c && c <= 'c') {
            c = '2';
        } else if ('d' <= c && c <= 'f') {
            c = '3';
        } else if ('g' <= c && c <= 'i') {
             c = '4';
        } else if ('j' <= c && c <= 'l') {
            c = '5';
        } else if ('m' <= c && c <= 'o') {
            c = '6';
        } else if ('p' <= c && c <= 's') {
            c = '7';
        } else if ('t' <= c && c <= 'v') {
            c = '8';
        } else if ('w' <= c && c <= 'z') {
            c = '9';
        }
    }
    cout << str << endl;
}

int main()
{
    mima();

    return 0;
}


#华为笔试#
全部评论

相关推荐

点赞 评论 收藏
分享
asdasdasdasdas:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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