题解 | #字符串加解密#

字符串加解密

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;

}

全部评论

相关推荐

09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
09-24 18:30
已编辑
长春工业大学 产品经理
小肥罗:HR就是好人的缩写哈哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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