题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <iostream> using namespace std; #include<string> int main() { string preCode, afterCode; cin >> preCode >> afterCode; string s1 = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}; string s2 = {"BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza1234567890"}; string preCode2; string afterCode2; for (int i = 0; i < preCode.size(); i++) { if ((preCode[i] >= 'a' && preCode[i] <= 'z') || (preCode[i] >= 'A' && preCode[i] <= 'Z') || (preCode[i] >= '0' && preCode[i] <= '9')) { int index; index = s1.find(preCode[i]); preCode2 += s2[index]; } else { preCode2 += preCode[i]; } } for (int i = 0; i < afterCode.size(); i++) { if ((afterCode[i] >= 'a' && afterCode[i] <= 'z') || (afterCode[i] >= 'A' && afterCode[i] <= 'Z') || (afterCode[i] >= '0' && afterCode[i] <= '9')) { int index; index = s2.find(afterCode[i]); afterCode2 += s1[index]; } else { afterCode2 += afterCode[i]; } } cout << preCode2 << endl; cout << afterCode2 << endl; }