题解 | #字符串加解密#

字符串加解密

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;

}

全部评论

相关推荐

Dream_coding:你是不是只投大厂了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务