题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.on('line', function (line) { console.log(line.length > 8 && check1(line) && check2(line) ? 'OK' : 'NG'); }); function check1(line: string){ let count = [0,0,0,0] const arr = line.split('') for(let c of arr){ if('A' <= c && 'Z' >= c) count[0] = 1 else if('a' <= c && 'z' >= c) count[1] = 1 else if(/^[0-9]$/.test(c)) count[2] = 1 else if(c !== '' && c !== '\n' ) count[3] = 1 } return count.reduce((sum,cur)=>sum+cur) >= 3 } function check2(line: string){ const set = new Set() for(let i = 0; i < line.length - 3; i++){ const str = line.slice(i, i + 3) if(set.has(str)) return false set.add(str) } return true }