题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <bits/stdc++.h>
using namespace std;
int numb1(char n){
if(n=='9') return '0';
else return n+1;
}
int numb2(char n){
if(n=='0') return '9';
else return n-1;
}
int alp1(char n){
if(n>='a'&&n<'z') return n-31;
else if(n=='z') return 'A';
else if(n>='A'&&n<'Z') return n+33;
else return 'a';
}
int alp2(char n){
if(n>'a'&&n<='z') return n-33;
else if(n=='a') return 'Z';
else if(n>'A'&&n<='Z') return n+31;
else return 'z';
}
int main(){
string m,n;
while(cin>>m>>n){
for(int i=0;i<m.size();++i){
if(isalpha(m[i])) m[i]=alp1(m[i]);
else m[i]=numb1(m[i]);
}
for(int i=0;i<n.size();++i){
if(isalpha(n[i])) n[i]=alp2(n[i]);
else n[i]=numb2(n[i]);
}
cout<<m<<endl<<n<<endl;
}
return 0;
}