题解 | #字符串加解密#

字符串加解密

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    // while(line = await readline()){
    //     let tokens = line.split(' ');
    //     let a = parseInt(tokens[0]);
    //     let b = parseInt(tokens[1]);
    //     console.log(a + b);
    // }
    let decodeStrs = await readline();
    let encodeStrs = await readline();

    let strs = "";
    for (let s of decodeStrs) {
        if (/[0-9]/.test(s)) {
            if (s === "9") {
                strs += "0";
            } else {
                strs += String.fromCharCode(s.charCodeAt() + 1);
            }
        }

        if (/[a-z]/.test(s)) {
            if (s === "z") {
                strs += "A";
            } else {
                strs += String.fromCharCode(s.charCodeAt() - 31);
            }
        }

        if (/[A-Z]/.test(s)) {
            if (s === "Z") {
                strs += "a";
            } else {
                strs += String.fromCharCode(s.charCodeAt() + 33);
            }
        }
    }
    console.log(strs);
    strs = "";
    for (let s of encodeStrs) {
        if (/[0-9]/.test(s)) {
            if (s === "0") {
                strs += "9";
            } else {
                strs += String.fromCharCode(s.charCodeAt() - 1);
            }
        }

        if (/[a-z]/.test(s)) {
            if (s === "a") {
                strs += "Z";
            } else {
                strs += String.fromCharCode(s.charCodeAt() - 33)
            }
        }

        if (/[A-Z]/.test(s)) {
            if (s === "A") {
                strs += "z";
            } else {
                strs += String.fromCharCode(s.charCodeAt() + 31);
            }
        }
    }
    console.log(strs);
})();

全部评论

相关推荐

每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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