题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let index = 0;
let input = [];
rl.on("line", function (line) {
solution(line);
});
function solution(line: string) {
if (line.length <= 8) {
console.log("NG");
return;
}
let UpperLetter = /[A-Z]/.test(line);
let LowerLetter = /[a-z]/.test(line);
let num = /[0-9]/.test(line);
let other = /[^A-Za-z0-9]/.test(line);
let count = [UpperLetter, LowerLetter, num, other]
.map((x) => Number(x))
.reduce((a, b) => a + b, 0);
if (count < 3) {
console.log("NG");
return;
}
let set = new Set();
for (let i = 0; i < line.length && i + 3 <= line.length; i++) {
let subStr = line.substring(i, i + 3);
if (set.has(subStr)) {
console.log("NG");
return;
} else {
set.add(subStr);
}
}
console.log("OK");
}
顺丰集团工作强度 379人发布