题解 | #简单密码#

简单密码

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

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

int main() {
	//利用 map 表来解析代码
    map<char, char> ctoint;
    ctoint['a'] = '2';ctoint['b'] = '2';ctoint['c'] = '2';
    ctoint['d'] = '3';ctoint['e'] = '3';ctoint['f'] = '3';
    ctoint['g'] = '4';ctoint['h'] = '4';ctoint['i'] = '4';
    ctoint['j'] = '5';ctoint['k'] = '5';ctoint['l'] = '5';
    ctoint['m'] = '6';ctoint['n'] = '6';ctoint['o'] = '6';
    ctoint['p'] = '7';ctoint['q'] = '7';ctoint['r'] = '7';ctoint['s'] = '7';
    ctoint['t'] = '8';ctoint['u'] = '8';ctoint['v'] = '8';
    ctoint['w'] = '9';ctoint['x'] = '9';ctoint['y'] = '9';ctoint['z'] = '9';
    string str, ans;
    cin >> str;
    int len = str.length();
    for(int i = 0; i < len; i++){
        if(str[i] >= 'A' && str[i] <= 'Z'){
            char c = tolower(str[i]);
            if(c == 'z'){
                c = 'a';
            }else{
                c += 1;
            }
            ans.append(1, c);
        }else if(str[i] >= 'a' && str[i] <= 'z'){
            ans.append(1, ctoint[str[i]]);
        }else{
            ans.append(1, str[i]);
        }

    }

    cout << ans << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

码农索隆:传音老登来也。 但是这个我不知道怎么回答,不仅仅传音吧,很多公司在候选人不第一时间接受offer或主动将报道时间延期时,都会再从池子里面捞人,直到l捞到满足公司所有要求的人。
秋招的第一个offer,...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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