题解 | #密码验证合格程序#
密码验证合格程序
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(isQualify(line) ? 'OK' : 'NG') } }() function isQualify(str) { let type = 0 if (str.length < 9 || str.includes('\n') || str.includes(' ')) return false; if (/[a-z]/.test(str)) { // 小写字母 type++; } if (/[A-Z]/.test(str)) { // 大写字母 type++; } if (/[0-9]/.test(str)) { // 数字 type++; } // 其他符号(取反,非汉字非大小写非数字) if (/[^a-zA-z0-9]/.test(str)) type++; if(type < 3) return false; // 判断是否有长度大于 2 的包含公共元素的子串重复 for (let i = 0; i < str.length - 2; i++) { let b = str.split(str.slice(i, i+3)); if (b.length > 2) return false; } return true; }