题解 | #字符串加解密#
字符串加解密
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); })();