题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include<iostream> #include<string>//字符串 本质是一个类 using namespace std; int main() { string s = ""; string s1 = ""; cin >> s>>s1; //cout << s << endl; string st = ""; st = s[0]; for (int i = 1; i < s.size(); ++i)//去除重复 { if (st.find(s[i]) == -1) { st += s[i]; } } string ch ="abcdefghijklmnopqrstuvwxyz";//26个英文字母 for (int j = 0; j < 26; ++j) //将26字母中不存在的字母添加进st去 { if (st.find(ch[j]) == -1) { st += ch[j]; } } for (int i = 0; i < s1.size(); ++i) { cout << st[ch.find(s1[i])]; //将加密字符串的每个字母在26个字母中的位置找到 //然后输出st对应位置的字符 } cout << endl; system("pause"); return 0; }