题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
// HJ36 字符串加密.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<iostream> #include<bits/stdc++.h> using namespace std; int main() { string s, word; vector<bool>flag(26, false); string v; while (cin >> s >> word) { for (int i = 0; i < s.size(); i++) { s[i] = toupper(s[i]); if (flag[s[i]-'A']==false) { v.push_back(s[i]); flag[s[i] - 'A'] = 1; } } int len = v.size(); for (char i = 'A'; i <='Z'; i++) { if (flag[i-'A'] == false) { v.push_back(i); } } string output; for (int j = 0; j < word.size(); j++) { if (islower(word[j])) { output += v[word[j] - 'a'] + 32; } else if (isupper(word[j])) { output += v[word[j] - 'A']; } } cout << output << endl; } return 0; }