题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <iostream> #include <vector> #include <algorithm> #include <string> #include<unordered_set> using namespace std; int main(){ string mask; cin>>mask; vector<int> mp(26,-1); unordered_set<int> set; int idx=0; for(char c:mask){ if(c>='a'&&c<='z'){ if(set.count(c-'a')) continue; mp[idx++]=c-'a'; set.insert(c-'a'); }else if(c>='A'&&c<='Z'){ if(set.count(c-'A')) continue; mp[idx++]=c-'A'; set.insert(c-'A'); } } for(int i=0;i<26;i++){ if(set.count(i)) continue; if(idx>=26)cout<<"dog"; mp[idx++]=i; } string s; cin>>s; string res; for(char c:s){ if(c>='a'&&c<='z'){ res.push_back(mp[c-'a']+'a'); }else if(c>='A'&&c<='Z'){ res.push_back(mp[c-'A']+'A'); } } cout<<res; system("pause"); return 0; }