题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
#include <cctype> #include <iostream> #include <set> #include <unordered_map> #include <vector> using namespace std; int main() { set<char> tem; vector<char> dir(26); string s; string tosec; int count = 0; while(getline(cin,tosec)) { // 注意 while 处理多个 case getline(cin,s); for(int i=0;i<tosec.size();i++){ tosec[i] = tolower(tosec[i]); if(tem.find(tosec[i])==tem.end()){ tem.insert(tosec[i]); dir[count] = tosec[i]; count++; }else{ continue; } } for(int i = 0;i<26;i++){ if(tem.find('a'+i)==tem.end()){ tem.insert('a'+i); dir[count] = 'a'+i; count++; }else{ continue; } } for(int i = 0;i<s.size();i++){ if(s[i]>='a'&&s[i]<='z'){ s[i] = dir[s[i]-'a']; continue; } if(s[i]>='A'&&s[i]<='Z'){ s[i] = toupper(dir[s[i]-'A']); continue; } } cout<<s; } } // 64 位输出请用 printf("%lld")