题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include<iostream> #include<vector> #include<cstring> #include <string> using namespace std; void string_sre(string pd) { vector<char> ss; int len = pd.size(); for (int i = 0; i < len; i++) { if (isdigit(pd[i])) { int j; if (pd[i] == '9') j = char('0'); else j = (pd[i]) + 1; //cout << j<<endl; ss.push_back(char(j)); //cout << "数字"; //cout<<"j"<<j<<endl; } else if (isalpha(pd[i])) { char ch; if (pd[i] >= 'a' && pd[i] < 'z') { ch = toupper(pd[i])+1; //cout << "toupper(pd[i])+1:" << toupper(pd[i]) + 1 << endl; //cout << "ch:" << char(ch) << endl; //cout<<"a~z:"<<pd[i]<<endl; } else if (pd[i] >= 'A' && pd[i] < 'Z') { ch = tolower(pd[i])-1; } else if (pd[i] == 'Z') { ch = 'a'; } else if (pd[i] == 'z') { ch = 'A'; } //cout<<pd[i]; //cout << ch; ss.push_back(ch); } else ss.push_back(char(pd[i])); } for(int i=0;i<ss.size();i++) { cout<<ss[i]; } cout<<endl; }; int main() { string str; while (getline(cin, str)) { string_sre(str); } }
#接受加密字符串listuninput#