题解 | #简单密码#暴力解法
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include<iostream> #include<string> using namespace std; int passcodeChange(string str) { string strnew; for (int i = 0; i < str.size(); i++) { if (str[i] >= 'a' && str[i] <= 'z') { switch (str[i]) { case 'a': case 'b': case 'c': strnew.push_back('2'); break; case 'd': case 'e': case 'f': strnew.push_back('3'); break; case 'g': case 'h': case 'i': strnew.push_back('4'); break; case 'j': case 'k': case 'l': strnew.push_back('5'); break; case 'm': case 'n': case 'o': strnew.push_back('6'); break; case 'p': case 'q': case 'r': case 's': strnew.push_back('7'); break; case 't': case 'u': case 'v': strnew.push_back('8'); break; case 'w': case 'x': case 'y': case 'z': strnew.push_back('9'); break; default: break; } } else if (str[i] >= 'A' && str[i] <= 'Z') { if (str[i] == 'Z') { strnew.push_back('a'); } else { strnew.push_back(str[i] + 'a' - 'A' + 1); } } else { strnew.push_back(str[i]); } } cout << strnew << endl; return 0; } int main() { string str; while (cin >> str) { passcodeChange(str); } return 0; }
#华为笔试#