题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <cctype> #include <iostream> using namespace std; int main() { string s; while (getline(cin,s)) { // 注意 while 处理多个 case for(int i = 0;i<s.size();i++){ if(s[i]>='a'&&s[i]<='y'){ s[i] = toupper(s[i]+1); continue; }if(s[i]>='A'&&s[i]<='Y'){ s[i] = tolower(s[i]+1); continue; }if(s[i]=='z'){ s[i] = 'A'; continue; }if(s[i]=='Z'){ s[i] = 'a'; continue; } if(s[i]>='0'&&s[i]<='8'){ s[i] = toupper(s[i]+1); continue; }if(s[i]=='9'){ s[i] = '0'; continue; } } cout<<s<<endl; s.clear(); getline(cin,s); for(int i = 0;i<s.size();i++){ if(s[i]>='b'&&s[i]<='z'){ s[i] = toupper(s[i]-1); continue; }if(s[i]>='B'&&s[i]<='Z'){ s[i] = tolower(s[i]-1); continue; }if(s[i]=='a'){ s[i] = 'Z'; continue; }if(s[i]=='A'){ s[i] = 'z'; continue; } if(s[i]>='1'&&s[i]<='9'){ s[i] = toupper(s[i]-1); continue; }if(s[i]=='0'){ s[i] = '9'; continue; } } cout<<s<<endl; s.clear(); } } // 64 位输出请用 printf("%lld")