题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include<bits/stdc++.h>
using namespace std;
int main()
{
string key;
string str;
//1.先处理输入
cin >> key;
cin >> str;
//2.建立新的字母表
vector<int> used(26,0);
vector<char> alphabet;
for(auto ch : key)
{
if(used[ch-'a'])
{
continue;
}
else
{
alphabet.push_back(ch);
used[ch-'a'] = 1;
}
}
for(int i = 0; i < 26; i++)
{
if(used[i] == 1)
{
continue;
}
alphabet.push_back('a'+i);
}
//3.加密
string res;
for(auto ch : str)
{
res += alphabet[ch-'a'];
}
//4.处理输出
cout << res << endl;
return 0;
}