题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
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())) { // line = '%Z7'; // 长度要超过 8 位 if (line.length <= 8) { console.log("NG"); continue; } // 查找至少三种符号 let count = 0; if (/[A-Z]/.test(line)) { count++; } if (/[a-z]/.test(line)) { count++; } if (/[0-9]/.test(line)) { count++; } if (/[^A-Za-z0-9]/.test(line)) { count++; } if (count < 3) { console.log("NG"); continue; } let str1, str2; let arr = line.split(""); let isNG = false; if (arr.length >= 6) { for (let i = 0; i < arr.length - 6; i++) { str1 = arr.slice(i, i + 3).join(""); for (let j = i + 3; j < arr.length - 2; j++) { str2 = arr.slice(j, j + 3).join(""); if (str1 == str2) { isNG = true; break; } } if (isNG) { console.log("NG"); break; } } } if (!isNG) { console.log("OK"); } } })();