题解 | #字符串加解密#

字符串加解密

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;

}

全部评论

相关推荐

迷茫的大四🐶:都让开,我tm来啦
点赞 评论 收藏
分享
小肥罗:我觉得“实习生不了解也很正常”可能只是客套话,面试官的标准是希望答上来。另外,面试官没有马上结束面试,恰恰证明他想给你机会,想多考察你看你是否其他方面符合要求。面试时间长反而证明面试官还是看好你的,想多给你机会表现一下自己。
应届生简历当中,HR最关...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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