题解 | #简单密码#

简单密码

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

#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]) {
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size(); ++i) {
        if (str[i] >= 'a' && str[i] <= 'z') {
            if (str[i] == 'a' || str[i] == 'b' || str[i] == 'c') {
                str[i] = '2';
            }
            if (str[i] == 'd' || str[i] == 'e' || str[i] == 'f') {
                str[i] = '3';
            }
            if (str[i] == 'g' || str[i] == 'h' || str[i] == 'i') {
                str[i] = '4';
            }
            if (str[i] == 'j' || str[i] == 'k' || str[i] == 'l') {
                str[i] = '5';
            }
            if (str[i] == 'm' || str[i] == 'n' || str[i] == 'o') {
                str[i] = '6';
            }
            if (str[i] == 'p' || str[i] == 'q' || str[i] == 'r' || str[i] == 's') {
                str[i] = '7';
            }
            if (str[i] == 't' || str[i] == 'u' || str[i] == 'v') {
                str[i] = '8';
            }
            if (str[i] == 'w' || str[i] == 'x' || str[i] == 'y' || str[i] == 'z') {
                str[i] = '9';
            }
        }
        if (str[i] >= 'A' && str[i] <= 'Z') {
            str[i] = tolower(str[i]);
            if (str[i] == 'z') {
                str[i] = 'a';
            } else {
                str[i] += 1;
            }
        }
    }
    cout << str << endl;
}
全部评论

相关推荐

10-24 11:10
山西大学 Java
若梦难了:哥们,面试挂是很正常的。我大中厂终面挂,加起来快10次了,继续努力吧。
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务