题解 | #简单密码#

简单密码

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

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

int main() {
    string str_1;
    cin >> str_1;
    string str_2;
    for(int i = 0; i < str_1.length(); i++){
        if(str_1[i] >= 'A' && str_1[i] <= 'Z'){
            if(str_1[i] == 'Z') str_2 += 'a';
            else str_2 += str_1[i] + 33;
            continue;
        }
        else if(str_1[i] >= 'a' && str_1[i] <= 'z'){
            char tmp;
            switch (str_1[i]) {
                case 'a':
                case 'b':
                case 'c':
                    tmp = '2';
                    break;
                case 'd':
                case 'e':
                case 'f':
                    tmp = '3';
                    break;
                case 'g':
                case 'h':
                case 'i':
                    tmp = '4';
                    break;
                case 'j':
                case 'k':
                case 'l':
                    tmp = '5';
                    break;
                case 'm':
                case 'n':
                case 'o':
                    tmp = '6';
                    break;
                case 'p':
                case 'q':
                case 'r':
                case 's':
                    tmp = '7';
                    break;
                case 't':
                case 'u':
                case 'v':
                    tmp = '8';
                    break;
                case 'w':
                case 'x':
                case 'y':
                case 'z':
                    tmp = '9';
                    break;
            }
            str_2 += tmp;
        }
        else str_2 += str_1[i];
    }
    cout << str_2 << endl;
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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