题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <iostream> #include <vector> #include <string> using namespace std; int main() { string key, str; while (cin >> key >> str) { // true代表未出现过 string new_key; vector<bool> flag(26,true); // 对密钥key去重,生成短密钥new_key for (auto &i:key){ i = tolower(i); if (flag[i - 'a']){ // 一旦出现了,标记为false flag[i - 'a'] = false; new_key.push_back(i); } } // 补充密钥,生成字母表 string table = "abcdefghijklmnopqrstuvwxyz"; for (auto &i :table){ if (flag[i - 'a']){ new_key.push_back(i); } } string ciphertext = ""; for (auto &i:str){ ciphertext.push_back(new_key[i - 'a']); } cout << ciphertext; } return 0; }#23届找工作求助阵地##我的实习求职记录##14天打卡计划##零基础学习C++#