题解 | 密码验证合格程序
密码验证合格程序
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;
function doSlice(line) {
const n = line.split("").length;
let tempresult = new Map();
let flag = true;
for (let i = 0; i < n; i++) {
const str = line.substring(i,i+3);
if(tempresult.has(str)){
const lastIndex = tempresult.get(str);
//console.log(str,lastIndex,'重复',i)
//console.log(str,'重复');
if(i>=lastIndex+3){
flag=false;
return false;
}
}else{
tempresult.set(str,i);
}
}
//console.log(tempresult)
return flag;
}
void (async function () {
// Write your code here
while (line = await readline()) {
//校验长度
if(line.length<8){
console.log('NG');
continue;
}
//合法字符
let weight = 0;
if(/[a-z]/.test(line)){
weight++;
}
if(/[0-9]/.test(line)){
weight++;
}
if(/[A-Z]/.test(line)){
weight++;
}
if(/[^A-Za-z\s\d]/.test(line)){
weight++;
}
if(weight<3){
console.log('NG');
continue;
}
//字串校验
const result = doSlice(line);
if(!result){
console.log('NG');
}else{
console.log('OK');
}
//break;
}
})();
