题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include <iostream> #include <string> using namespace std; string Secure(string s){ string str; char arr[] = {"22233344455566677778889999"}; char brr[] = {"bcdefghijklmnopqrstuvwxyza"}; for (int i = 0; i < s.length(); i++){ if (s[i] >= 'a' && s[i] <= 'z'){ str += arr[s[i] - 'a']; } else if (s[i] >= 'A' && s[i] <= 'Z'){ str += brr[s[i] - 'A']; } else { str += s[i]; } } return str; } int main() { string str; while (cin >> str){ cout << Secure(str) << endl; } }