题解 | #字符串加解密#

字符串加解密

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;

}

全部评论

相关推荐

头像
11-09 17:30
门头沟学院 Java
TYUT太摆金星:我也是,好几个华为的社招找我了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务