题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <iostream>
#include <string>
#include <map>
#include <unordered_set>
using namespace std;
int main(int argc, char* argv[]){
string key;
cin >> key;
string code;
cin >> code;
unordered_set<char> occ;
auto iter = key.begin();
while(iter != key.end()){
if(occ.count(*iter)){
iter = key.erase(iter);
}
else{
occ.insert(*iter);
++iter;
}
}
map<char, char> dic;
for(int i = 0; i < key.size(); ++i){
dic['a' + i] = key[i];
}
for(int i = key.size(); i < 26; ++i){
int j = 0;
while(occ.count('a' + j)){
++j;
}
dic['a' + i] = 'a' + j;
occ.insert('a' + j);
}
for(int i = 0; i < code.size(); ++i){
cout << dic[code[i]];
}
cout << endl;
return 0;
}