HJ36 字符串加密
理解题意然后就很简单了
题目
代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void jiami(string key, string str){
vector<char> alpha(26);
string res = "";
int j = 0;
for(int i = 0; i < key.size(); i++){
if(std::find(alpha.begin(), alpha.end(), key[i]) == alpha.end()){
alpha[j++] = key[i];
}
}
for(int i = 0; i < 26; i++){
if(std::find(alpha.begin(), alpha.end(), 'a' + i) == alpha.end()){
alpha[j++] = 'a' + i;
}
}
for(int i = 0; i < str.size(); i++){
if('A' <= str[i] && str[i] <= 'Z' || 'a' <= str[i] && str[i] <= 'z'){
if('A' <= str[i] && str[i] <= 'Z'){
res += alpha[str[i] - 'A'];
}else if('a' <= str[i] && str[i] <= 'z'){
res += alpha[str[i] - 'a'];
}
}else{
res += str[i];
}
}
cout<<res;
}
int main(){
string key, str;
cin>>key>>str;
jiami(key, str);
return 0;
}
|