题解 | #字符串加解密#

字符串加解密

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;

}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 17:30
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 Java
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务