题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <iostream>
#include <map>
using namespace std;
string ch = "abcdefghijklmnopqrstuvwxyz";
int main(){
string key,str;
while (cin>>key>>str) {
map<char,bool> mp;
string newkey;
for (int i = 0; i < ch.size(); ++i) {
mp[ch[i]] = false;
}
for (int i = 0; i < key.size(); ++i) {
if (!mp[key[i]]){
newkey += key[i];
mp[key[i]] = true;
}
}
for(auto it : mp){
if (!it.second) {
newkey += it.first;
}
}
for (int i = 0; i < str.size(); ++i) {
str[i] = newkey[str[i]-'a'];
}
cout<<str<<endl;
}
return 0;
}
