题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <bits/stdc++.h>
using namespace::std;
int main() {
string sKey, sStr;
while (getline(cin, sKey) && getline(cin, sStr)) {
string str = "";
int kLen = sKey.size();
// 去重
for (int i = 0;i < kLen;i++) {
if (str.find(sKey[i]) == string::npos) {
str += sKey[i];
}
}
// 补剩余元素
for (int i = 0;i < 26;i++) {
if (str.find('a' + i) == string::npos) {
str += ('a' + i);
}
}
// 按密文字典对应位置输出
int sLen = sStr.size();
for (int i = 0;i < sLen;i++) {
cout << str[sStr[i] - 'a'];
}
cout << endl;
}
return 0;
}