题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <cctype> #include <iostream> using namespace std; void encode(string& s){ for(auto ch:s){ if(isalpha(ch)){ if((ch-'a')>=0){ ch = toupper(ch); if(ch=='Z')ch='A'; else ch++; } else{ ch = tolower(ch); if(ch=='z')ch='a'; else ch++; } cout<<ch; }else{ int t = ch-'0'; t++; cout<<t%10; } } cout<<endl; } void decode(string& s){ for(auto ch:s){ if(isalpha(ch)){ if((ch-'a')>=0){ if(ch=='a')ch='z'; else ch--; ch = toupper(ch); } else{ if(ch=='A')ch='Z'; else ch--; ch = tolower(ch); } cout<<ch; }else{ int t = ch-'0'; t--; cout<<(t+10)%10; } } cout<<endl; } int main() { char ch; string s1; string s2; cin>>s1>>s2; encode(s1); decode(s2); } // 64 位输出请用 printf("%lld")