题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <iostream> #include <vector> #include <string> #include <set> using namespace std; int main() { std::string secret; std::string info; cin >> secret; cin.ignore(); cin >> info; // 处理密钥, 剔除重复的字符 std::set<char> cc; std::string new_secret; for (char c : secret) { if (auto it = cc.find(c) == cc.end()) { new_secret.push_back(c); cc.insert(c); } } // 补充字母表 char i = 'a'; do { if (auto it = cc.find(i) == cc.end()) { new_secret.push_back(i); } i++; } while (i <= 'z'); // 对明文里的每个字符查字母表 std::string ret; for (char c : info) { int idx = c - 'a'; ret += new_secret[idx]; } std::cout << ret << std::endl; return 0; }