题解 | #简单密码#

简单密码

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

#include <iostream>
#include<string>

using namespace std;

int value[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9};

int main() {
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size(); i++) {
        if (str[i] >= 65 && str[i] < 90) { //处理大写字母
            cout << char(str[i] + 32 + 1);
        } else if (str[i] == 90) { //单独处理“Z”
            cout << 'a';
        } else if (str[i] >= 97 && str[i] <= 122) { //处理小写字母
            cout << value[str[i] - 'a'];
        } else {
            cout << str[i];
        }
    }

    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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