题解 | #字符串加解密#

字符串加解密

https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

#include <iostream>
using namespace std;
#include<string>


int main() {
    string preCode, afterCode;
    cin >> preCode >> afterCode;
    string s1 = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"};
    string s2 = {"BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza1234567890"};
    string preCode2;
    string afterCode2;
    for (int i = 0; i < preCode.size(); i++) {
        if ((preCode[i] >= 'a' && preCode[i] <= 'z') || (preCode[i] >= 'A' &&
                preCode[i] <= 'Z') || (preCode[i] >= '0' && preCode[i] <= '9')) {
            int index;
            index = s1.find(preCode[i]);
            preCode2 += s2[index];
        } else {
            preCode2 += preCode[i];
        }
    }
    for (int i = 0; i < afterCode.size(); i++) {
        if ((afterCode[i] >= 'a' && afterCode[i] <= 'z') || (afterCode[i] >= 'A' &&
                afterCode[i] <= 'Z') || (afterCode[i] >= '0' && afterCode[i] <= '9')) {
            int index;
            index = s2.find(afterCode[i]);
            afterCode2 += s1[index];
        } else {
            afterCode2 += afterCode[i];
        }
    }
    cout << preCode2 << endl;
    cout << afterCode2 << endl;

}

全部评论

相关推荐

2025-11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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