题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include <iostream> #include<string> #include<map> using namespace std; int main() { string str; cin >> str; map<char, int> mp; mp['a'] = 2; mp['b'] = 2; mp['c'] = 2; mp['d'] = 3; mp['e'] = 3; mp['f'] = 3; mp['g'] = 4; mp['h'] = 4; mp['i'] = 4; mp['j'] = 5; mp['k'] = 5; mp['l'] = 5; mp['m'] = 6; mp['n'] = 6; mp['o'] = 6; mp['p'] = 7; mp['q'] = 7; mp['r'] = 7; mp['s'] = 7; mp['t'] = 8; mp['u'] = 8; mp['v'] = 8; mp['w'] = 9; mp['x'] = 9; mp['y'] = 9; mp['z'] = 9; for (auto cc : str) { map<char, int>::iterator it = mp.begin(); if (cc >= '0' && cc <= '9') { cout << cc; } for (; it != mp.end(); it++) { if (cc == it->first) { cout << it->second; break; } else if (cc >= 'A' && cc <= 'Z') { if (cc == 'Z') { cc = 'a'; cout << cc; break; } cc = cc + 32 + 1; cout << cc; break; } } } }