题解 | #字符串加密#
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
可以使用哈希表查看是否重复
#include<bits/stdc++.h> using namespace std; int main(){ string key; cin >> key; map<char, int> buffer; vector<char> alpha(26); int position = 0; for(char ch : key){ if(!buffer.count(ch)){ alpha[position] = ch; buffer[ch] = 1; position++; } } for(char ch = 'a'; ch < 'z' + 1; ch++){ if(!buffer.count(ch)){ alpha[position] = ch; buffer[ch] = 1; position++; } } string toBeDealt; while(cin >> toBeDealt){ for(char &ch : toBeDealt){ ch = alpha[ch - 'a']; } cout << toBeDealt << ' '; } return 0; }