思路:
主要是处理好对应的关系
代码:
#include<iostream>
#include<string>
using namespace std;
int main(){
string s1,s2;
cin>>s1>>s2;
//s1加密
for(int i = 0; i < s1.size(); i++){
char &c = s1[i];
if(c >= 'a' && c <= 'z'){
if(c == 'z') c = 'A';
else c = c - 31;
}
else if(c >= 'A' && c <= 'Z'){
if(c == 'Z') c = 'a';
else c = c + 33;
}
else if(isdigit(s1[i])){
if(c == '9') c = '0';
else c++;
}
else continue;
}
cout<<s1<<endl;
for(int i = 0; i < s2.size(); i++){
char &c = s2[i];
if(c >= 'a' && c <= 'z'){
if(c == 'a') c = 'Z';
else c = c - 33;
}
else if(c >= 'A' &&c <= 'Z'){
if(c == 'A') c = 'z';
else c = c + 31;
}
else if(isdigit(c)){
if(c == '0') c = '9';
else c--;
}
else continue;
}
cout<<s2;
return 0;
}
评论区