题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <bits/stdc++.h>
using namespace::std;
void trans(string &str, const uint flag)
{
string code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
string ecode[2] = {("bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890"), \
("zabcdefghijklmnopqrstuvwxyZABCDEFGHIJKLMNOPQRSTUVWXY9012345678")};
for (auto &c : str) {
if (isupper(c)) {
c = ecode[flag][c - 'A'];
} else if (islower(c)) {
c = ecode[flag][c - 'a' + 26];
} else if (isdigit(c)) {
c = ecode[flag][c - '0' + 52];
}
}
cout << str << endl;
}
int main()
{
int i = 0;
string str;
while (getline(cin, str)) {
trans(str, i++%2);
}
return 0;
}