题解 | 简单密码

简单密码

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

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

int main() 
{
    string input;
    cin >> input;
    int len = input.size();
    string output;
    for(char c : input){
        if(c >= 'a' && c <= 'c'){
            output.push_back('2');
        }else if(c >= 'd' && c <= 'f'){
            output.push_back('3');
        }else if(c >= 'g' && c <= 'i'){
            output.push_back('4');
        }else if(c >= 'j' && c <= 'l'){
            output.push_back('5');
        }else if(c >= 'm' && c <= 'o'){
            output.push_back('6');
        }else if(c >= 'p' && c <= 's'){
            output.push_back('7');
        }else if(c >= 't' && c <= 'v'){
            output.push_back('8');
        }else if(c >= 'w' && c <= 'z'){
            output.push_back('9');
        }else if(c >= 'A' && c <= 'Z'){
            if(c == 'Z'){
                c = 'a';
                output.push_back(c);
                continue;
            }
            output.push_back(c - 'A' + 'a' + 1);
        }else if(c >= '0' && c <= '9'){
            output.push_back(c);
        }
    }
    cout << output << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-25 17:23
做完了怎么知道过没过呀
投递京东等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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