题解 | #密码验证合格程序#
密码验证合格程序
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
let lines = [];
while ((line = await readline())) {
method(line);
}
})();
function method(s) {
if (Zimu(s) + Num(s) + otherSign(s) < 3) {
console.log("NG");
return;
}
if (!isNotRepeat(s)) {
console.log("NG");
return;
}
if (s.length <= 8) {
console.log("NG");
return;
}
console.log("OK");
}
function Zimu(s) {
let da = 0;
let xiao = 0;
for (let i = 0; i < s.length; i++) {
if (s.charCodeAt(i) >= 65 && s.charCodeAt(i) <= 90) {
da = 1;
}
if (s.charCodeAt(i) >= 97 && s.charCodeAt(i) <= 122) {
xiao = 1;
}
}
return da + xiao;
}
function Num(s) {
for (let i = 0; i < s.length; i++) {
if (s.charCodeAt(i) >= 49 && s.charCodeAt(i) <= 57) {
return 1;
}
}
return 0;
}
function otherSign(s) {
for (let i = 0; i < s.length; i++) {
let count = 0;
if (s.charCodeAt(i) >= 48 && s.charCodeAt(i) <= 57) {
count++;
}
if (s.charCodeAt(i) >= 65 && s.charCodeAt(i) <= 90) {
count++;
}
if (s.charCodeAt(i) >= 97 && s.charCodeAt(i) <= 122) {
count++;
}
if (count == 0) {
return 1;
}
}
return 0;
}
function isNotRepeat(s) {
let arr = [];
for (let i = 0; i < s.length - 2; i++) {
let sub = s.substring(i, i + 3);
// console.log(sub);
if (arr.indexOf(sub) == -1) {
arr.push(sub);
} else {
return false;
}
}
return true;
}
查看16道真题和解析
