题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <iostream> #include <unordered_set> using namespace std; int main() { string key, str; while (cin >> key >> str) { unordered_set<char> st; string ans = ""; //获取密码中不重复的字符 for (int i = 0; i < key.size(); i++) { if (st.count(key[i])) { continue; } else { st.insert(key[i]); ans += key[i]; } } //组织成新的密码 for (int j = 0; j < 26; j++) { if (st.count(j + 'a')) continue; else ans += (j + 'a'); } //解码 for (int i = 0; i < str.size(); i++) { str[i] = ans[str[i] - 'a']; } cout << str << endl; } return 0; }