题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
string jiami(string &s){
for(int i = 0 ; i < s.size(); ++i){
if(islower(s[i])){
s[i] = (s[i] - 'a' + 1)%26+'A' ;
}else if(isupper(s[i])){
s[i] = (s[i] - 'A' +1)%26 +'a';
}else if(isdigit(s[i])){
s[i] = (s[i] - '0' +1)%10 +'0';
}
}
return s;
}
string jiemi(string &s){
for(int i = 0 ; i < s.size(); ++i){
if(islower(s[i])){
s[i] = (s[i] - 'a' +25)%26+'A' ;
}else if(isupper(s[i])){
s[i] = (s[i] - 'A' +25 )%26 +'a';
}else if(isdigit(s[i])){
s[i] = (s[i] - '0' + 9 )%10 +'0';
}
}
return s;
}
int main(){
while(cin>>s1>>s2){
string out1=jiami(s1);
string out2=jiemi(s2);
cout<<out1<<endl;
cout<<out2<<endl;
}
}