题解 | #密码验证合格程序#
密码验证合格程序
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())) { console.log(check(line)); } function check(str) { let result = "OK"; if (str.length < 8) { result = "NG"; } let arr = [/[A-Z]/g, /[a-z]/g, /[0-9]/g, /[^\w]|_/g]; let n = 0; arr.forEach((item) => { if (item.test(str)) n++; }); if (n < 3) { result = "NG"; } for (let i = 0; i < str.length - 2; i++) { let s = str.substr(i, 3); if (str.includes(s, i + 3)) { result = "NG"; break; } } return result; } })();