当前位置:   article > 正文

华为od机试题(js篇)_华为od require("readline").createinterface({ input:

华为od require("readline").createinterface({ input: process.stdin })

01-108题

第1题:
在这里插入图片描述
答案:
const readline = require(“readline”);

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on(“line”, function (line) {

const tokens = line.split(" ");
console.log(tokens[tokens.length-1].length)
  • 1
  • 2

});

第2题:
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
const line = await readline();
const code = await readline();

function findSum(str, s) {
    const res = str.toLocaleLowerCase();
    return res.split(s.toLocaleLowerCase()).length - 1;
}
console.log(findSum(line, code));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

})();

第3题:
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {
// Write your code here

const arr = []
while(line = await readline()){
    arr.push(line)
}
const temp = [...new Set(arr.slice(1))]
temp.sort((a,b)=>{
    return a-b
})
temp.forEach(item=>(console.log(item)))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

}()

第4题:
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
// Write your code here

let input = await readline();
function output(input) {
    if (input.length > 8) {
        console.log(input.substring(0, 8));
        output(input.substring(8));
    } else {
        console.log(input.padEnd(8, "0"));
    }
}
output(input);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

})();

第5题:
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
const str = await readline()
console.log(parseInt(str,16))
  • 1
  • 2
  • 3

}()

第6题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
let num = Number(await readline())
let res = []
for(let i=2;i*i<=num;i++){
    while(num%i===0){
        res.push(i)
        num/=i
    }
}
if(num>1){
    res.push(num)
}
console.log(res.join(' ').trim())
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

}()

第7题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
const num = await readline()
const res = parseFloat(num)
console.log(Math.round(res))
  • 1
  • 2
  • 3
  • 4

}()

第8题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
let obj = {};
while ((line = await readline())) {
    const list = line.split(" ");
    const key = parseInt(list[0]);
    const value = parseInt(list[1]);
    if (value) {
        if (obj[key]) {
            obj[key] += value;
        } else {
            obj[key] = value;
        }
    }
}
for (key in obj) {
    console.log(key + " " + obj[key]);
}

// // 1. 创建一个空对象来接收键值对
// let obj = {};
// // 2. 传入字符串数据
// while ((str = await readline())) {
//     // 3. 将字符串变成数组,并用一个变量接收
//     let arr = str.split(" ");
//     // 4. 用两个变量接收处理好的 arr 的两项数据,两项已经变成数字类型的数据
//     let a = parseInt(arr[0]);
//     let b = parseInt(arr[1]);

//     // 5. 判断数组 arr 的第二项数据是否为零, 为零则不符合要求
//     if (b) {
//         // 6. 如果 obj 的键(属性名)存在,或者说键名重复了 ,则键(属性名相同)的值相加
//         if (obj[a]) {
//             obj[a] += b;
//         } else {
//             // 7. 如果 obj 没有相同的 键(属性名),或者说是没有这个键名 ,就存储相应的value
//             obj[a] = b;
//         }
//     }
// }

// // 8. 遍历 obj 对象,将 键值对的值输出
// for (key in obj) {
//     console.log(key + " " + obj[key]);
// }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

})();

第9题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    const list = line.toString().split('').reverse()
    const res =[...new Set(list)] 
    console.log(Number(res.join('')))
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()

第10题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    let tokens = line.split('');
    const res = [...new Set(tokens)]
    console.log(res.length)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()

第11题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    let tokens = line.split('').reverse();
    let res = tokens.join('')
    console.log(res)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()

第12题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    let tokens = line.split('');
    let res = tokens.reverse().join('')
    console.log(res)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()

第13题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    let tokens = line.split(' ');
    let res = tokens.reverse().join(' ')
    console.log(res)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()

第14题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
let list = []
while(line = await readline()){
    list.push(line)
}
const resList = list.sort().slice(1)
resList.forEach(item=>{
    console.log(item)
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

}()
第15题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    const num = parseInt(line).toString(2)
    console.log(num.match(/1/g).length)
}
  • 1
  • 2
  • 3
  • 4
  • 5

}()

第16题
在这里插入图片描述

第17题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {
// Write your code here
let result = []
let i = 0
let j = 0
while(line = await readline()){
let list = line.split(‘;’)
list.forEach(item=>{
if(Number(item.slice(1))){
switch(item[0]){
case ‘A’:
i-=Number(item.slice(1))
break;
case ‘D’:
i+=Number(item.slice(1))
break;
case ‘S’:
j-=Number(item.slice(1))
break;
case ‘W’:
j+=Number(item.slice(1))
break;
default:
break
}
}
})
result.push(i)
result.push(j)
console.log(result.join(‘,’))
}
}()

第18题
在这里插入图片描述
第19题
在这里插入图片描述

第20题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    console.log(quality(line) ? "OK" : "NG");
    function quality(str) {
        let [correct, count] = [0, 0];
        if (str.length < 9 || str.includes("\n") || str.includes(" ")) return false;
        if (/[a-z]/.test(str)) {
            correct++;
        }
        if (/[A-Z]/.test(str)) {
            correct++;
        }
        if (/[1-9]/.test(str)) {
            correct++;
        }
        if (/[^\u4e00-\u9fa5a-zA-Z\d,\.,。]+/.test(str)) correct++;
        if (correct < 3) return false;
        const obj ={}
        for (let i = 0; i < str.length; i++) {
            let substring = str.substring(i, i + 3);
            if (substring.length < 3) continue;
            obj[substring] = null;
            count++;
        }
        return Object.keys(obj).length === count;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

})();
第21题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    let base = {
        2: "abc",
        3: "def",
        4: "ghi",
        5: "jkl",
        6: "mno",
        7: "pqrs",
        8: "tuv",
        9: "wxyz",
    };
    let str1 = line.replace(/[a-z]/g, (x) => {
        for (let key in base) {
            if (base[key].includes(x)) {
                x = key;
                return x;
            }
        }
    });
    let str2 = str1.replace(/[A-Z]/g, (x) => {
        x =
            x === "Z"
                ? 'a'
                : String.fromCharCode(x.toLowerCase().charCodeAt(0) + 1);
        return x;
        
    });
    console.log(str2);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

})();
第22题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    if(line!=="0"){
        console.log(Math.floor(parseInt(line)/2))
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()

第23题
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    let tokens = line.split("");
    let result = tokens.reduce((temp, data) => {
        temp[data] = temp[data] ? temp[data] + 1 : 1;
        return temp;
    }, {});
    
    let min = 21;
    for (let index in result) {
        min = Math.min(min, result[index]);
    }
    for (let index in result) {
        if (result[index] === min) {
            const rep = new RegExp(index,'g')
            line = line.replace(rep, "");
        }
    }
    console.log(line)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

})();

在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
let lineArr = []
while(line = await readline()){
    lineArr.push(line)
}
let arr = lineArr[1].split(' ').map(e => Number(e))
let firstDp = solution(arr) // 从左至右去处理数组
let secondDp = solution(arr.reverse()).reverse() // 将数组反转,从右至左去处理,然后再进行反转
let max = 0
for(let i = 0; i < firstDp.length; i++){
    // 找出递增数列最多的那个
    max = Math.max(max, firstDp[i] + secondDp[i] - 1)
}
// arr.length-max则表示需要删除多少项,才可以形成队列
console.log(arr.length - max)
/**
 * 函数是为了将从数组的一项,增加到多项,然后把每一项都进行比较。
 * 如果第j项比第i项要小,那就说明是可以形成递增的数列,让dp[i] = Math.max(dp[i], dp[j]+1).
 * dp是用来存储第i项的递增数列的个数
 * 如果dp[i]比dp[j]+1要大,那么则保持原样,如果要小,则dp[i]赋值为dp[j+1]
 */
function solution(arr) {
    let dp = []
    for(let i = 0; i < arr.length; i++){
        dp[i] = 1
        for(let j = 0; j < i; j++){
            if(arr[j] < arr[i]) {
                dp[i] = Math.max(dp[i], dp[j] + 1)
            }
        }
    }
    return dp
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

}()
在这里插入图片描述
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {
// Write your code here
var arr = [];
while(line = await readline()){
arr.push(line);
}

var iArr = arr[0].split(' ').slice(1);
var rArr = [...new Set(arr[1].split(' ').slice(1).map(item => Number(item)))];
rArr.sort((a,b) => a -b);
rArr = rArr.map(item => item.toString());
var o = {};
for(var i = 0; i < rArr.length; i++) {
    var result = [];
    for(var k = 0; k < iArr.length; k++) {
        if(iArr[k].indexOf(rArr[i]) > -1) {
            result.push([iArr[k], k]);
            o[rArr[i]] = result;
        }
    }
}

var res = '';
rArr.forEach((item) => {
    if(o[item]) {
        res = res +  ' ' + item + ' ' + o[item].length;
        o[item].forEach(item2 => {
            res = res + ' ' + item2[1] + ' ' + item2[0];
        });            
    }
             
})
var count = res.trim().split(' ').length;
console.log(`${count}${res}`)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

}()
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        /**
         * 具体思想:
         * 1. 先将字母都提取出来
         * 2. 将提取出来的字母排序,排序规则是都先转换成大写,比较ASCII数字的大小
         * 3. 在将排序好的字符串1个个的原样替换输入的字符串位置(非字符串的位置跳过)
         */
        var arr = line.split('');
        var char = [];
        // 提取字符串
        for(var i = 0; i < arr.length; i++) {
            if(/[a-zA-Z]/.test(arr[i])) {
                char.push(arr[i]);
            }
        }
        // 排序提取的字符串
        char.sort((a, b) => {
            var ascA = a.toUpperCase().charCodeAt();
            var ascB = b.toUpperCase().charCodeAt();
            return ascA - ascB;
        });
 
        // 原样插入到输入字符串
        var k = 0;
        for (var j = 0; j < arr.length; j++) {
            if(/[a-zA-Z]/.test(arr[j])) {
                arr[j] = char[k];
                k++;
            }
        }
 
        console.log(arr.join(''));
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

}()

在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
// Write your code here

 while ((line = await readline())) {
        let n = Number(line);
        let odd = [];
        let even = [];
        // 把数据分成奇数和偶数,因为奇数+偶数才能得出奇数,所有素数除了2以外都是奇数
        (await readline()).split(" ").forEach((v) => {
            v = Number(v);
            if (v % 2 === 0) {
                even.push(v);
            } else {
                odd.push(v);
            }
        });

        if (odd.length == 0 || even.length == 0) {
            console.log(0);
            return;
        }
        // 遍历并找到所有素数伴侣
        const map = [];
        for (let i = 0; i < odd.length; i++) {
            map[i] = new Array(even.length);
            for (let j = 0; j < even.length; j++) {
                map[i][j] = isPrime(odd[i] + even[j]);
            }
        }

        let count = 0;
        let usedEven = []; // 存放每次遍历里面的偶数下标,防止无限递归
        let matchArr = []; // matchArr[j]存放偶数j对应的奇数下标i
        for (let i = 0; i < odd.length; i++) {
            if (isMach(i)) {
                count++;
                usedEven = [];
            }
        }

        console.log(count);

        function isMach(i) {
            for (let j = 0; j < even.length; j++) {
                // i、j对应的奇偶数的话如果不是素数或者当前偶数下标在这次isMach递归中已经使用过则直接跳过当前循环
                if (!map[i][j] || usedEven[j]) continue;
                usedEven[j] = true;
                // 如果j没有匹配过,或者原来跟j匹配的奇数matchArr[j]能找到其他匹配
                if (matchArr[j] === undefined || isMach(matchArr[j])) {
                    matchArr[j] = i;
                    return true;
                }
            }
            return false;
        }
        function isPrime(n) {
            let res = true;
            for (let i = 2; i * i <= n; i++) {
                if (n % i === 0) {
                    res = false;
                }
            }
            return res;
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

})();
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
// 有限数据量,直接枚举出全部,查表就可以了

 let str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    let str2 = "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890";
    let data = [];
    while ((line = await readline())) {
        data.push(line);
    }
    let arr1 = []; //解密后的字符集合;
    let arr2 = []; // 加密后的字符集合
    for (char of data[0]) {
        arr1.push(str2[str1.indexOf(char)]);
    }
    console.log(arr1.join(""));
    for (char of data[1]) {
        arr2.push(str1[str2.indexOf(char)]);
    }
    console.log(arr2.join(""));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

})();
在这里插入图片描述
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

 // Write your code here
    let input,arr1 = [],arr2 = [],resArr = []
    while(line = await readline()){
        input = line.split(' ').join('').split('');
    }
    //拆分输入的字符串,分别传入奇数组、偶数组
    input.forEach((e,i)=>{
        if(i%2===0){
            arr2.push(e)
        }else{
            arr1.push(e)
        }
    })
    //字母排序
    arr2.sort()
    arr1.sort()
    //按奇偶下标添加到结果数组内
    for(let i=0;i<arr2.length;i++){
        resArr.push(arr2[i])
        if(arr1[i]){
            resArr.push(arr1[i])
        }
    }
    //二进制翻转
    const reverse2 = (str) => {
        let res =  parseInt(str,16).toString(2)
        while(res.length<4){
            res = '0' + res
        }
        return parseInt(res.split('').reverse().join(''),2).toString(16).toUpperCase()
    }
    const reg = /^[0-9A-Fa-f]$/
    for(let i=0;i<resArr.length;i++){
        if(reg.test(resArr[i])){//符合正则的字符进行二进制翻转
            resArr[i] = reverse2(resArr[i])
        }
    }
    console.log(resArr.join(''))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

})();
在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

  // Write your code here
    let str = await readline()
    str = str.replace(/[^A-Za-z]/g, ' ')
    let result = str.split(' ').reverse().join(' ')
    console.log(result)
  • 1
  • 2
  • 3
  • 4
  • 5

}()
在这里插入图片描述
答案:

const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    var arr = line.replaceAll("", "#").split("");
    arr.push("*");
    arr.unshift("~");
    var res = 0;
    for (var i = 1; i < arr.length; i++) {
        var s = dfs(arr[i], i - 1, i + 1, arr);
        s = s.replace(/[#*~]/g, "");
        res = Math.max(res, s.length);
    }

    function dfs(cur, l, r, arr) {
         if (l < 0 || r > arr.length || arr[l] !== arr[r]) {
             return cur;
         }
         return dfs(arr[l] + arr[r] + cur, l - 1, r + 1, arr);
     }
     console.log(res);
    }
})();


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

在这里插入图片描述
答案:
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

 // Write your code here
    let lineArr = [];
    while ((line = await readline())) {
        lineArr.push(line);
    }
    let first = lineArr[0].split(".");
    let second = lineArr[1];
    // IP地址转十进制
    let ipStr = "";
    for (let i = 0; i < first.length; i++) {
        // toString(2)转二进制,padStart()方法用于补足字符串前面,直到指定长度
        let temp = Number(first[i]).toString(2).padStart(8, "0");
        ipStr += temp;
    }
    console.log(parseInt(ipStr, 2)); // 转为十进制
    // 十进制转IP地址
    let changeStr = Number(second).toString(2).padStart(32, "0");
    let changeArr = []; // 用于存储八位二进制的数组
    for (let i = 0; i < 32; i += 8) {
        changeArr.push(changeStr.slice(i, i + 8));
    }
    let strArr = changeArr.map((item) => parseInt(item, 2)); // 将数组的每一项转十进制
    console.log(strArr.join("."));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

})();
在这里插入图片描述

const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
         let arr1=line.match(/[0-9]/g).sort()
        let arr2=line.match(/[A-Z]/g).sort()
        let arr3=line.match(/[a-z]/g).sort()
        let arr=[...arr1,...arr2,...arr3]
        console.log(arr.join(''))
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

  let n = await readline();
    //定义开始每一行的第一个数值为num,默认为1
    let num = 1;
    //定义一个空数组,用来接收每行输出的数值
    let arr = [];
    //循环n次,得到每一行的第一个数值为num = 前一行的值 + 索引  第一行为1+0=1  第二行为1+1=2  第三行为2+2=4  第四行为4+3=7....

    for (let i = 0; i < n; i++) {
        num += i;
        let firstNum = num; //得到第一列 1  2 4 7...
        //第一行  第二个数firstNum=前一个数 + 索引+1 ,将得到的值存入数组
        for (let j = i + 1; j <= n; j++) {
            arr.push(firstNum);
            firstNum += j + 1;
        }
        console.log(arr.join(" "));
        arr = []; //清空数组
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

})();
在这里插入图片描述

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 inputArr = [];
    while ((line = await readline())) {
        inputArr.push(line);
    }
    const key = inputArr[0];
    const word = inputArr[1];
    const originTable = "abcdefghijklmnopqrstuvwxyz"; //原字母表
    const table = [...new Set(key + originTable)].join(""); //结合key生成的打乱的字母表
    let result = "";
    for (k of word) {
        let index = originTable.indexOf(k); // 找出在原表中的位置
        result += table[index]; //从新表中按照位置取出对应字母拼接新的单词
    }
    console.log(result);
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

在这里插入图片描述

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
    // 斐波那契数列 1 1  2 3 5 8 13 21,从第三项开始,后面一项等于前面2项的和
    function febo(n) {
        if (n === 1 || n === 2) return 1;
        if (n >= 3) {
            return febo(n - 2) + febo(n - 1);
        }
    }
    while ((line = await readline())) {
        const month = Number(line);
        console.log(febo(month));
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while(line = await readline()){
        var h = Number(line);
        var count = 0;  // 落地的次数
        var distance = 0;  // 走的总长
        var _h = 0;  // 每次的反弹高度
 
        while( count < 5) {
            count < 4 ? (distance += h*3/2) : (distance += h);
            _h = h = h / 2;
            count++;          
        }
        console.log(distance);
        console.log(_h);
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

在这里插入图片描述

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

 // Write your code here
    while ((line = await readline())) {
        var e = line.match(/[a-zA-Z]/g);
        var s = line.match(/\s/g);
        var d = line.match(/\d/g);
        var q = line.match(/[^a-zA-Z0-9\s]/g);
        e ? console.log(e.length) : console.log(0);
        s ? console.log(s.length) : console.log(0);
        d ? console.log(d.length) : console.log(0);
        q ? console.log(q.length) : console.log(0);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    const listAll = []
    while(line = await readline()){
        listAll.push(line)
    }
    const weightList = listAll[1].split(' ').map(item=>Number(item))
    const numberList = listAll[2].split(' ').map(item=>Number(item))
    const targetSet = new Set()
    targetSet.add(0)
    for(let i=0;i<weightList.length;i++){
        const arr = [...targetSet]
        for(let j=0;j<=numberList[i];j++){
            arr.forEach(item=>targetSet.add(item+weightList[i]*j))
        }
    }
    console.log(targetSet.size)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

}()
在这里插入图片描述
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

  // Write your code here
    while ((line = await readline())) {
        let [n, m] = line.split(" ").map(Number);
        //输入转二维数组
        let arr = [];
        for (let i = 0; i < n; i++) {
            let l = await readline();
            arr.push(l.split(" ").map(Number));
        }

        function dfs(stack) {
            let cur = stack[stack.length - 1];
            if (cur[0] === n - 1 && cur[1] === m - 1) {
                stack.forEach((v) => {
                    console.log(`(${v[0]},${v[1]})`);
                });
                return stack;
            }
            let left = [cur[0], cur[1] - 1],
                right = [cur[0], cur[1] + 1],
                top = [cur[0] - 1, cur[1]],
                bottom = [cur[0] + 1, cur[1]];
            //向左搜索
            if (valid(stack, left)) {
                let tempStack = [...stack];
                tempStack.push(left);
                dfs(tempStack);
            }
            //向右搜索
            if (valid(stack, right)) {
                let tempStack = [...stack];
                tempStack.push(right);
                dfs(tempStack);
            }
            //向上搜索
            if (valid(stack, top)) {
                let tempStack = [...stack];
                tempStack.push(top);
                dfs(tempStack);
            }
            //向下搜索
            if (valid(stack, bottom)) {
                let tempStack = [...stack];
                tempStack.push(bottom);
                dfs(tempStack);
            }
        }
        //检查路线是否合理(未到边界以及当前没有障碍)
        function valid(stack, pos) {
            if (
                pos[0] >= 0 &&
                pos[0] <= n - 1 &&
                pos[1] >= 0 &&
                pos[1] <= m - 1 &&
                !stack.find(
                    (item) => item[0] === pos[0] && item[1] === pos[1]
                ) &&
                arr[pos[0]][pos[1]] !== 1
            ) {
                return true;
            }
            return false;
        }
        dfs([[0, 0]]);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

})();
在这里插入图片描述
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
let n = await readline()
while(line = await readline()){
    let obj = {}
    let count = 0
    for(let i=0;i<line.length;i++){
        obj[line[i]] = obj[line[i]]?obj[line[i]]+1:1
    }
    let ddd =Object.entries(obj)
    ddd.sort((a,b)=>{
        return Number(b[1])-Number(a[1]) 
    })
    for(let j=0;j<ddd.length;j++){
        count+=(ddd[j][1])*(26-j)
    }
    console.log(count)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    const list = []
    while(line = await readline()){
          list.push(line)
    }
     console.log(list[0].slice(0,Number(list[1])))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

 // Write your code here
    while ((line = await readline())) {
        let [length,head,...tail] = line.split(' ')
        let del =  tail.pop()
        let link = [head]
        while(tail.length){
            const [save,target,...rail] = tail
            tail = rail
            const index = link.indexOf(target)
            link.splice(index+1,0,save)
        }
        const delIndex = link.indexOf(del)
        link.splice(delIndex,1)
        console.log(link.join(' '))
        
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    let s = line
        .replace(/\{/g, "(")
        .replace(/\}/g, ")")
        .replace(/\[/g, "(")
        .replace(/\]/g, ")");
    
    const d = new Function(
        `return ${s}` 
    )
    console.log(d())
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

  // Write your code here
    while (
        ((line = await readline()),
        (str = await readline()),
        (pos = await readline()))
    ) {
        const arr = str.split(" ");
        // 倒数索引获取数组的元素
        console.log(arr.at(-pos));
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

   // Write your code here
    let lineArr = [];
    while ((line = await readline())) {
        lineArr.push(line);
    }
    const [first,second] = lineArr
    const firstlength = first.split('').length
    const secondlength = second.split('').length
    let dp = new Array(firstlength+1).fill(0).map(()=> new Array(secondlength+1).fill(0))
    for(let i=1;i<=firstlength;i++){
        dp[i][0] = i
    }
    for(let j=1;j<=secondlength;j++){
        dp[0][j] = j
    }
    for(let i=1;i<=firstlength;i++){
        for(let j=1;j<=secondlength;j++){
            if(first[i-1]===second[j-1]){
                dp[i][j] = dp[i-1][j-1]
            }else{
                dp[i][j] =1+ Math.min(dp[i-1][j-1],dp[i][j-1],dp[i-1][j])
            }
        }
    }
    console.log(dp[firstlength][secondlength])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        if(line==1||line==2) console.log(-1)
        else if(line%2===1) console.log(2)
        else if(line%4===0) console.log(3)
        else console.log(4)
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        const ddd = Function(`return ${line}`)
        console.log(ddd())
    }
  • 1
  • 2
  • 3
  • 4
  • 5

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        const num = Number(line)
        const list = []
        for(let i=1;i<=num;i++){
            if(i%7===0||i.toString().includes('7')){
                list.push(i)
            }
        }
        console.log(list.length)
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

 // Write your code here
    while ((line = await readline())) {
        let num = Number(line)
        let result = 0
        for(let i=2;i<num;i++){
            let temp = 0 
            for(let j=1;j<i;j++){
                if(i%j===0){
                    temp+=j
                }
            }
            if(temp===i){
                result++
            }
        }
        console.log(result)
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

})();

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    const list= []
    while(line = await readline()){
        list.push(line)
    }
    const num1 = BigInt(list[0])
    const num2 = BigInt(list[1])
    console.log((num1+num2).toString())
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

  // Write your code here
    const list = []
    while(line = await readline()){
        list.push(line)
    }
    const data = list[1].split(' ').sort((a,b)=>{
        return a-b
    })
    const index = list[0].split(' ')[1]
    console.log(data.slice(0,index).join(' '))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        for(let i=0;i<line.length;i++){
            if(line.indexOf(line[i])===line.lastIndexOf(line[i])){
                console.log(line[i])
                return
            }
        }
        console.log(-1)
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        const number = Number(line)
        for(let i=Math.floor(number/2) ;i>=0;i--){
            if(isrequired(i)&&isrequired(number-i)){
                console.log(i)
                console.log(number-i)
                return
            }
        }
    }

    function isrequired(num){
        for(let i=2;i<=Math.sqrt(num);i++){
            if(num%i===0)return false
        }
        return true
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        const arr = line.split(' ')
        const appelNum =Number(arr[0]) 
        const panziNum =Number(arr[1]) 
        
        console.log(count(appelNum,panziNum))  
    }
    function count(m,n){
        if(m<0||n<=0)return 0
        else if(m===1||n===1)return 1
        else{
            return count(m,n-1)+count(m-n,n)
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

}()

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

  // Write your code here
    while(line = await readline()){
        const num2 =Number(line).toString(2)
        const list = num2.match(/1/g)
        console.log(list.length)
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
const list = []
while(line = await readline()){
    list.push(line)
}
let str = list[0]
let num = Number(list[1]) 

let initNum = 0
let resStr = ''
for(let i=0;i<str.length-num+1;i++){
    const substrs = str.substr(i,num)
    let count = 0
    for(key of substrs){
        if(key==='C'||key==='G'){
            count++
        }

    }
    if(count>initNum){
        initNum = count
        resStr = substrs
    }
}
console.log(resStr)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

}()

在这里插入图片描述
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    const data = []
    while(line = await readline()){
        data.push(line)
    }
    const [first,second] = data
    const minstr = first.length>second.length?second:first
    const maxstr = first.length>second.length?first:second
    const minlength = minstr.length
    let max = 0
    let str = ''
    for(let i=0;i<minlength;i++){
        for(j=i+1;j<minlength;j++){
            const substrs = minstr.slice(i,j)
            const lengths = substrs.length
            if(maxstr.includes(substrs)&&lengths>max){
                max = lengths
                str = substrs
            }
        }
    }
    console.log(str)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

}()

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        const list1 = ['reset','board','board','reboot','backplane']
        const list2 = ['board','add','delete','backplane','abort']
        const list3 = ['board fault','where to add','no board at all','impossible','install first']
        const list = line.split(' ')
        if(list.length===1){
            if('reset'.indexOf(line)===0){
                console.log('reset what')
            }else{
                console.log('unknown command')
            }
        }else{
            let [first,second] = list
            let num = 0
            let index = 0
            for(let i=0;i<list1.length;i++){
                if(list1[i].indexOf(first)===0&&list2[i].indexOf(second)===0){
                    num++
                    index = i
                }
            }
            if(num===1){
                console.log(list3[index])
            }else{
                console.log('unknown command')
            }
        }
        
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

  // Write your code here
    let status; // 设置一个状态来表示是否可以得到24
    while ((line = await readline())) {
        let lineArr = line.split(" ").map((e) => Number(e));
        status = false; // 状态默认为false,如果可以得到24,则将state置为true
        solution(-1, 0, lineArr); // 这里step设置为0,是因为一进去就是step++,变为0,pre为0,是因为未进行四则运算的初始值
        console.log(status);
    }
    /**
     * 类似于深度优先
     * step为运算次数,pre是进行任意四则运算的结果,arr为初始数组
     */
    function solution(step, pre, arr) {
        if (step === 3) {
            // 已经运算四次
            if (pre === 24) {
                // 如果得到的数为24
                status = true;
                return;
            }
        } else {
            step++; // 每次运算,step加一
            for (let i = 0; i < arr.length; i++) {
                let newArr = JSON.parse(JSON.stringify(arr)); // 不改变原始数组,还可以使用arr.slice()和arr.concat()也不会改变原数组,只会生成一个数组副本,返回给newArr
                let num = newArr.splice(i, 1)[0]; // 删除新数组的每一项的后面一位作为四则运算,splice()会返回一个包含删除的那些数据项的新数组,会改变原数组
                solution(step, pre + num, newArr);
                solution(step, pre - num, newArr);
                solution(step, pre * num, newArr);
                solution(step, pre / num, newArr);
            }
            return;
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

let arr = [];
void (async function () {

  // Write your code here
    while ((line = await readline())) {
        arr.push(line);
    }
    let order = arr[1];
    let result = arr.slice(2).map((v) => v.split(" "));
    if (order == 1) {
        result.sort((a, b) => a[1] - b[1]);
    } else {
        result.sort((a, b) => b[1] - a[1]);
    }
    result.forEach((el) => console.log(el.join(" ")));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

let arr = [];
let arrA = [];
let arrB = [];

void (async function () {

  // Write your code here
    let x = await readline();
    let y = await readline();
    let z = await readline();
    while ((line = await readline())) {
        arr.push(line);
    }
    for (let i = 0; i < Number(x); i++) {
        arrA.push(arr[i].split(" ").map(Number));
    }
    for (let i = Number(x); i < arr.length; i++) {
        arrB.push(arr[i].split(" ").map(Number));
    }
    computeRec(arrA, arrB);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

})();

function computeRec(arrA, arrB) {
// 初始化数组
// let res = new Array(arrA.length).fill([]).map(arr=>{
// new Array(arrB[0].length).fill(0)
// })

// 注意!!!!!!
// 超级大坑:如果按上面那种方式创建数组的话,之后如果你想修改a[0][0]的值为x的话,你会发现a[1][0],a[2][0]等同一列的值全都会变
// 我在这里停了好久找不到哪里错
// 参考:https://juejin.cn/post/6968645442691137572
/**
 * 按这种方式老老实实创建吧
 * let res = new Array(arrA.length);
   for (let i = 0; i < res.length; i++) {
    res[i] = new Array(arrB[0].length).fill(0);
   }
 * 
 *  */
// let res = new Array(arrA.length);
// for (let i = 0; i < res.length; i++) {
//     res[i] = new Array(arrB[0].length).fill(0);
// }

// 另一个大神写的
let res = Array.from(new Array(arrA.length), () =>
    new Array(arrB[0].length).fill(0)
);
// 选取第几行
for (let i = 0; i < arrA.length; i++) {
    // 选取第几列
    for (let j = 0; j < arrB[0].length; j++) {
        // 中间的k值变动
        for (let k = 0; k < arrA[0].length; k++) {
            res[i][j] += arrA[i][k] * arrB[k][j];
        }
    }
}
// 输出
for (let i = 0; i < res.length; i++) {
    let temp = res[i].join(" ");
    console.log(temp);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

}

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
let data = [];
rl.on(“line”, function (line) {
data.push(line);
});

rl.on("close", function () {
    // 解法1:考察栈的使用
    let [count, ...tail] = data;
    let str = tail.pop(); // 计算法则
    let matrixs = tail.map((item) => item.trim().split(" ")); // 矩阵
    let res = 0; // 乘积次数
    let track = []; // 初始化一个栈
    // 根据计算法则:
    // 左括号:什么也不做
    // 右括号:入栈
    // 左括号:出栈
    // 规则:出栈时,弹出两个矩阵,先弹出的矩阵位置应该排后弹出的矩阵之后
    // 并将弹出的矩阵的乘积再重新入栈
    for (let i = 0; i < str.length; i++) {
        if (str[i] == ")") {
            let right = track.shift(); // 右边的矩阵
            let left = track.shift(); // 左边的矩阵
            track.unshift([left[0], right[1]]);
            res += left[0] * left[1] * right[1];
        } else if (/[A-Za-z]/.test(str[i])) {
            track.unshift(matrixs.shift());
        }
    }
    console.log(res);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

   // Write your code here
    let reg = await readline();
    const s = await readline();

    reg = reg.replace(/\*/g, "\\w*").replace(/\?/g, "\\w").toLowerCase();
    const r = new RegExp(reg);
    const res = s.match(r);
    if (res === null) {
        console.log(false);
        return;
    }
    if (res[0] === s) {
        console.log(true);
        return;
    }
    console.log(false);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

  // Write your code here
    while ((line = await readline())) {
        // 构造三层for循环,满足条件打印
        for (let x = 0; x < 20; x++) {
            for (let y = 0; y < 33; y++) {
                for (let z = 0; z < 100; z = z + 3) {
                    if (5 * x + 3 * y + z / 3 === 100 && x + y + z === 100) {
                        console.log(`${x} ${y} ${z}`);
                    }
                }
            }
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

})();

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

 // Write your code here
    while(line = await readline()){
        let data = [31,28,31,30,31,30,31,31,30,31,30,31]
        let [year,month,day] = line.split(' ')
        let count = 0
        for(let i=0;i<Number(month)-1;i++){
            count+=data[i]
        }
        count+=Number(day)
        if(Number(month)>2&&(year%4===0&&year%100!==0||year%400===0)){
            count+=1
        }
        console.log(count)
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

}()

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    var s = line;
    // 解析引号
    var sigles = s.match(/".*?"/g);
    s = s.replace(/".*?"/g, "#");
    console.log(s)
    var arr = s.split(" ");
    console.log(arr);
    arr.forEach((item) => {
        if (item === "#") {
            item = sigles.shift().replace(/"/g, "");
        }
        console.log(item);
    });
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
let data = [];
while ((line = await readline())) {
    data.push(line);
}
let [str1, str2] = data;
let minstr = str1.length > str2.length ? str2 : str1;
let maxstr = str1.length > str2.length ? str1 : str2;
let max = 0;
for (let i = 0; i < minstr.length; i++) {
    for (let j = i + 1; j <= minstr.length; j++) {
        const substrs = minstr.slice(i, j);
        if (maxstr.indexOf(substrs) > -1 && substrs.length > max) {
            max = substrs.length;
        }
    }
}
console.log(max);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

})();

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    const num = Number(line)
    let count = num*(num-1)+1 
    let result = count
    for(let i=1;i<num;i++){
        const addnum = count+i*2
        result+='+'+addnum
    }
    console.log(result)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

// Write your code here
while ((line = await readline())) {
    let n = Number(line);
    let trains = (await readline()).split(" ");
    let res = [];
    backtrack(0, [], []);
    console.log(res.sort().join("\n"));
    function backtrack(i, out, stack) {
        if (out.length === n) {
            res.push(out.join(" "));
            return;
        }
        // 先进站,要回溯
        if (stack.length >= 0 && i < n) {
            stack.push(trains[i]);
            backtrack(i + 1, out.slice(), stack.slice());
            stack.pop();
        }
        // 出站
        if (stack.length > 0 && i <= n) {
            out.push(stack.pop());
            backtrack(i, out, stack);
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
const data = []
while(line = await readline()){
    data.push(line)
}
const list1 = data[1].split(' ')
const list2 = data[3].split(' ')
const list = list1.concat(list2)
const reslist = [...new Set(list)].sort((a,b)=>{
    return Number(a) - Number(b)
}).join('')
console.log(reslist)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
let data = []
while(line = await readline()){
    data.push(line)
}
let str1 = data[0]
let str2 = data[1]
let minstr = str1.length>str2.length?str2:str1
let maxstr = str1.length>str2.length?str1:str2
let minlist = minstr.split('')
let status = true
minlist.forEach(item=>{
    if(!maxstr.includes(item)){
        status = false
    }
})
console.log(status)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

/**
数学家斐波那契提出的一种求解***分数的贪心算法,准确的算法表述应该是这样的:
设某个真分数的分子为a,分母为b;
把c=(b/a+1)作为分解式中第一个***分数的分母;
将a-b%a作为新的a;
将b*c作为新的b;
如果a等于1,则最后一个***分数为1/b,算法结束;
如果a大于1但是a能整除b,则最后一个***分数为1/(b/a),算法结束;
否则重复上面的步骤。
**/
void (async function () {
    // Write your code here
    while ((line = await readline())) {
        const tokens = line.split("/");
        let a = parseInt(tokens[0]);
        let b = parseInt(tokens[1]);
        let r = "";
        while (true) {
            let c = Math.floor(b / a) + 1;
            a = a - (b % a);
            b = b * c;
            r = r + `1/${c}+`;
            if (a === 1) {
                r = r + `1/${b}`;
                break;
            } else if (a > 1 && b % a === 0) {
                r = r + `1/${b / a}`;
                break;
            }
        }
        console.log(r);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {

let linearr = [];
while ((line = await readline())) {
    linearr.push(line);
}
let inputarr = []; //初始化要循环判断的数组
for (let i = 0; i < linearr.length; i += 5) {
    //每5个一组
    inputarr.push(linearr.slice(i, i + 5));
}
// console.log(inputarr);
inputarr.forEach((item) => {
    //判断行列数
    let rowCol = item[0].split(" ").map(Number);
    let [row, col] = rowCol;
    if (row > 9 || col > 9) {
        console.log(-1);
    } else {
        console.log(0);
    }
    //判断交换的坐标值
    let exchangeXy = item[1].split(" ").map(Number);
    if (
        exchangeXy[0] > row - 1 ||
        exchangeXy[2] > row - 1 ||
        exchangeXy[1] > col - 1 ||
        exchangeXy[3] > col - 1
    ) {
        console.log(-1);
    } else {
        console.log(0);
    }
    //判断插入行
    // 插入行的数字不能大于索引的最大值,总行数不能超过9
    let addRow = Number(item[2]);
    if (addRow > row - 1 || row === 9) {
        console.log(-1);
    } else {
        console.log(0);
    }
    //判断插入列
    // 插入列的数字不能大于索引的最大值,总列数不能超过9
    let addCol = Number(item[3]);
    if (addCol > col - 1 || col === 9) {
        console.log(-1);
    } else {
        console.log(0);
    }
    //判断查询值
    let queryXy = item[4].split(" ").map(Number);
    let [querRow, querCol] = queryXy;
    if (querRow > row - 1 || querCol > col - 1) {
        console.log(-1);
    } else {
        console.log(0);
    }
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

})();
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    const list = line.match(/[A-Z]/g)
    console.log(list.length)
}
  • 1
  • 2
  • 3
  • 4
  • 5

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    let maxLength = 0
    for(let i=0;i<line.length;i++){
        for(let j=i+1;j<=line.length;j++){
            const substrs = line.slice(i,j)
            if(substrs===substrs.split('').reverse().join('')&&substrs.length>maxLength){
                maxLength=substrs.length
            }
        }
    }
    console.log(maxLength)
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {

// Write your code here
while(line = await readline()){
    const number = String(Number(line).toString(2)) 
    const list = number.match(/1+/g)
    const max = Math.max(...list)
    console.log(String(max).length)
    
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

}()
在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while ((line = await readline())) {
        let score = 0;
        // 密码长度
        let linelength = line.length;
        if (linelength <= 4) {
            score += 5;
        } else if (linelength >= 5 && linelength <= 7) {
            score += 10;
        } else {
            score += 25;
        }
        // console.log(score)
        // 字母
        let minWord = line.match(/[a-z]/g);
        let maxWord = line.match(/[A-Z]/g);
        let minlength = minWord?.length || 0;
        let maxlength = maxWord?.length || 0;
        if (minlength === 0 && maxlength === 0) {
            score += 0;
        } else if (
            (minlength === 0 && maxlength) ||
            (maxlength === 0 && minlength)
        ) {
            score += 10;
        } else {
            score += 20;
        }
        // console.log(score)
        // 数字
        let numlist = line.match(/[0-9]/g);
        let numLength = numlist?.length||0;
        if (numLength === 0) {
            score += 0;
        } else if (numLength === 1) {
            score += 10;
        } else {
            score += 20;
        }
        // console.log(score)
        // 字符
        const wordlist = line.match(/[^a-zA-Z0-9]/g);
        const wordlength = wordlist?.length||0;
        if (wordlength === 0) {
            score += 0;
        } else if (wordlength === 1) {
            score += 10;
        } else {
            score += 25;
        }
        // console.log(score)

        // 奖励
        if (minlength && maxlength && numLength && wordlength) {
            score += 5;
        } else if ((minlength || maxlength) && numLength && wordlength) {
            score += 3;
        } else if ((minlength || maxlength) && numLength) {
            score += 2;
        }
        // console.log(score)
        if (score >= 90) {
            console.log("VERY_SECURE");
        } else if (score >= 80 && score < 90) {
            console.log("SECURE");
        } else if (score >= 70 && score < 80) {
            console.log("VERY_STRONG");
        } else if (score >= 60 && score < 70) {
            console.log("STRONG");
        } else if (score >= 50 && score < 60) {
            console.log("AVERAGE");
        } else if (score >= 25 && score < 50) {
            console.log("WEAK");
        } else {
            console.log("VERY_WEAK");
        }
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79

在这里插入图片描述

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

const reg = /joker|JOKER/;

const getType = (a) => {
    const len = a.length;
    const s = [...new Set(a)];
    const slen = s.length;
    if (len === 1) {
        return 1;
    } else if (slen === 1) {
        return len; // 234
    } else if (len === 2 && a.every((aa) => reg.test(aa))) {
        return 6; // 王炸
    } else if (len >= 5) {
        return 5;
    }
};
const arr = [
    0,
    "3",
    "4",
    "5",
    "6",
    "7",
    "8",
    "9",
    "10",
    "J",
    "Q",
    "K",
    "A",
    "2",
    "joker",
    "JOKER",
];

void (async function () {
    // Write your code here
    const line = await readline();
    const [a, b] = line.split("-").map((aa) => aa.split(" "));
    const atype = getType(a);
    const btype = getType(b);

    if (atype === btype) {
        if (arr.indexOf(a[0]) > arr.indexOf(b[0])) {
            console.log(a.join(" "));
            return;
        }
        console.log(b.join(" "));
        return;
    } else {
        if (atype === 6) {
            console.log(a.join(" "));
            return;
        }
        if (btype === 6) {
            console.log(b.join(" "));
            return;
        }
        if (atype === 4) {
            console.log(a.join(" "));
            return;
        }
        if (btype === 4) {
            console.log(b.join(" "));
            return;
        }

        console.log("ERROR");
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74

在这里插入图片描述

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // 参考隔壁python大佬代码,转换成对应的js语法
    function permutation(s) {
        let path = [];
        let res = [];
        function dfs() {
            if (path.length === 4) {
                res.push([...path]);
                return;
            }

            for (let i = 0; i < 4; i++) {
                if (s[i] != "None") {
                    let cur = s[i];
                    path.push(cur);
                    s[i] = "None";
                    dfs();
                    path.pop();
                    s[i] = cur;
                }
            }
        }

        dfs();
        res = Array.from(new Set(res.map((it) => it.join(""))));
        // console.log("res: ", res);
        // res: [
        //   '42KA', '42AK', '4K2A',
        //   '4KA2', '4A2K', '4AK2',
        //   '24KA', '24AK', '2K4A',
        //   '2KA4', '2A4K', '2AK4',
        //   'K42A', 'K4A2', 'K24A',
        //   'K2A4', 'KA42', 'KA24',
        //   'A42K', 'A4K2', 'A24K',
        //   'A2K4', 'AK42', 'AK24'
        // ]
        return res;
    }

    function calculate(s) {
        let oper = "+-*/";
        for (let n of s) {
            for (let i of oper) {
                for (let j of oper) {
                    for (let t of oper) {
                        let fun =
                            "(" +
                            "(" +
                            dic[n[0]] +
                            i +
                            dic[n[1]] +
                            ")" +
                            j +
                            dic[n[2]] +
                            ")" +
                            t +
                            dic[n[3]];
                        if (eval(fun) == 24) {
                            return n[0] + i + n[1] + j + n[2] + t + n[3];
                        }
                    }
                }
            }
        }

        return "NONE";
    }

    var dic = {
        2: "2",
        3: "3",
        4: "4",
        5: "5",
        6: "6",
        7: "7",
        8: "8",
        9: "9",
        10: "10",
        J: "11",
        Q: "12",
        K: "13",
        A: "1",
    };

    // let s = ["4", "2", "K", "A"]; 对应res输出注释,方便大家参考
    let s = (await readline()).split(" ");

    if (s.includes("joker") || s.includes("JOKER")) {
        console.log("ERROR");
    } else {
        s = permutation(s);
        console.log(calculate(s));
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while ((line = await readline())) {
        let status = "YES";
        //判断除了数字和 . 以外有没有其他字符
        if (/[^0-9\.]/.test(line)) status = "NO";
        // .的个数为3
        let arrOfdot = line.split("").filter((i) => i === ".");
        if (arrOfdot.length !== 3) status = "NO";
        //以.拆分得到的数组每个位置不能为空字符串
        // 每个数在0-255之间
        // 每个数如果大于0的时候不能以0开头
        let arr = line.split(".");
        arr.forEach((item) => {
            if (item.length === 0) return (status = "NO");
            if (Number(item) < 0 || Number(item) > 255) return (status = "NO");
            if (Number(item) > 0 && item.startsWith(0)) return (status = "NO");
        });
        console.log(status);
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

function fn(m, n) {
    if (m == 0 || n == 0) {
        return 1;
    } else {
        return fn(m - 1, n) + fn(m, n - 1);
    }
}
void (async function () {
    // Write your code here
    while ((line = await readline())) {
        line = line.split(" ");
        var num = fn(Number(line[0]), Number(line[1]));
        console.log(num);
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

在这里插入图片描述
const rl = require(“readline”).createInterface({ input: process.stdin });
var iter = rlSymbol.asyncIterator;
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        // let line ='o0593'
        const numlist = line.match(/[0-9]+/g)
        let maxlenth =0
        numlist.forEach(item=>{
            if(item.length>maxlenth){
                maxlenth=item.length
            }
        })
        const list = []
        numlist.forEach(item=>{
            if(maxlenth===item.length){
                list.push(item)
            }
        })
        console.log(list.join('')+','+maxlenth)
    }
}()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

在这里插入图片描述

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
let k=0; 
let n = 0;
let nums = [];
void (async function () {
    // Write your code here
    while ((line = await readline())) {
        if (k === 0) {
            n = Number(line);
            k++;
        } else {
            nums = line.split(" ").map((e) => Number(e));
            getArr();
        }
    }
})();
function getArr() {
    let multi5 = [];
    let multi3 = [];
    let others = [];
    for (let i = 0; i < nums.length; i++) {
        if (nums[i] % 3 === 0 && nums[i] % 5 !== 0) {
            multi3.push(nums[i]);
        } else if (nums[i] % 5 === 0) {
            multi5.push(nums[i]);
        } else {
            others.push(nums[i]);
        }
    }
    let sum5 =
        multi5.length > 0
            ? multi5.reduce((prev, current) => prev + current)
            : 0;
    let sum3 =
        multi3.length > 0
            ? multi3.reduce((prev, current) => prev + current)
            : 0;
    console.log(isExists(sum5, sum3, others, 0));
}

function isExists(sum5, sum3, others, index) {
    if (others.length === 0 && sum5 !== sum3) {
        return false;
    } else if (others.length === 0 && sum5 === sum3) {
        return true;
    } else if (others.length === index && sum5 !== sum3) {
        return false;
    } else if (others.length === index && sum5 === sum3) {
        return true;
    } else if (index < others.length) {
        return (
            isExists(sum5 + others[index], sum3, others, index + 1) ||
            isExists(sum5, sum3 + others[index], others, index + 1)
        );
    } else {
        return false;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

在这里插入图片描述

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 lineArr = [];
    while ((line = await readline())) {
        lineArr.push(line);
    }
    let legalArr = lineArr[1].split(" ");
    let voteArr = lineArr[3].split(" ");
    let obj = {}; // 用来存储每个候选人的票数
    legalArr.forEach((item) => (obj[item] = 0)); // 将每个候选人的票数设置为0
    let invalidNum = 0; // 用来累加无效票数
    voteArr.forEach((item) => {
        if (legalArr.includes(item)) {
            obj[item]++;
        } else {
            invalidNum++;
        }
    });
    for (let key in obj) {
        console.log(`${key} : ${obj[key]}`);
    }
    console.log(`Invalid : ${invalidNum}`);
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

在这里插入图片描述

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    while ((line = await readline())) {
        let [num1, num2] = line.split(".");
        const strs = num1
            .replace(/(?=(\d{4})+$)/g, ".")
            .split(".")
            .filter(Boolean); // 从后往前,每4位一组 ['30','2345']
        const chars = [
            "零",
            "壹",
            "贰",
            "叁",
            "肆",
            "伍",
            "陆",
            "柒",
            "捌",
            "玖",
        ];
        const unit = ["", "拾", "佰", "仟"];
        const bigUnit = ["", "万", "亿"];
        //转换4位以下的数字的方法
        function _tranform(numStr) {
            let result = "";
            for (let i = 0; i < numStr.length; i++) {
                const digit = +numStr[i];
                const c = chars[digit];
                const u = unit[numStr.length - i - 1];
                if (digit == 0) {
                    //如果当前位置上字符为‘0’
                    // 如果当前result末尾已经是零,则不拼接;不是'零',才可以拼接上这个零;
                    //保证中间有多个0时只读一个零,如3001;
                    if (result[result.length - 1] !== chars[0]) {
                        result += c; //而且为零的拼接时不要单位
                    }
                } else {
                    result += c + u;
                }
            }
            // 如果最后末尾还是零的话,说明是形如'3000'或'3010'这种,需要处理一下
            if (result[result.length - 1] === chars[0]) {
                result = result.slice(0, -1);
            }
            return result;
        }
        // console.log(_tranform('1090'))
        let result = "人民币";
        //处理整数部分 num1 -> strs
        for (let i = 0; i < strs.length; i++) {
            const part = strs[i];
            const c = _tranform(part);
            const u = c ? bigUnit[strs.length - i - 1] : "";
            result += c + u;
        }
        // console.log(result);
        if (result !== "人民币") {
            result = (result + "元").replace(/壹拾/g, "拾");
        }
        //处理小数部分 num2 角和分
        if (num2 == "00") {
            result += "整";
        } else {
            if (num2[0] !== "0") {
                result += chars[num2[0]] + "角";
            }
            if (num2[1] !== "0") {
                result += chars[num2[1]] + "分";
            }
        }
        console.log(result);
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76

在这里插入图片描述

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()){
        const list = line.replace(/\d+/g,e=>{
            return '*'+e+'*'
        })
        console.log(list)
    }
}()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在这里插入图片描述

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 n = await readline();
    while ((line = await readline())) {
        let arr = line.split(" ").filter((item) => item == Math.abs(item));
        let len = n - arr.length;
        let num = 0;
        arr = arr.filter((item) => item != 0);
        arr.forEach((el) => {
            num += parseInt(el);
        });
        if (num > 0) {
            let average = (num / arr.length).toFixed(1);
            console.log(len + " " + average);
        } else {
            console.log(0 + " " + "0.0");
        }
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

在这里插入图片描述
在这里插入图片描述

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())) {
        var n = Number(line);
        var count = 0;
        for (var i = 0; i <= n; i++) {
            var tar = Math.pow(i, 2) + "";
            var cur = i + "";
            var c = tar.substr(-cur.length);
            if (c === cur) {
                count++;
            }
        }
        console.log(count);
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

在这里插入图片描述

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()){
        let num = Number(line)
        let minNum = 2
        let maxNum = 2 + 3 * (num - 1)
        let result = (minNum + maxNum) * num / 2
        console.log(result)
    }
}()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在这里插入图片描述

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 [len, arrStr, type] = [await readline(), await readline(), await readline()];
    const _arr = arrStr.split(' ').sort((a, b) => type === '0' ? a - b : b - a);
    console.log(_arr.join(' '));
}()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在这里插入图片描述

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 line = await readline(),
        map = new Map();
    line = line.split("");
    line.forEach((e) => {
        if (map.has(e)) map.set(e, map.get(e) + 1);
        else map.set(e, 1);
    });
    let res = Array.from(new Set(line));
    res = res.sort((a, b) => {
        if (map.get(a) < map.get(b)) return 1;
        else if (map.get(a) == map.get(b)) return a > b ? 1 : -1;
        else return -1;
    });
    console.log(res.join(""));
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

在这里插入图片描述

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    //     关于初始化
    // 数组 dp 中存储着对应 nums 位置的桩最大次数,所以创建的时候默认为 1,因为当前桩本身就是一步。

    // 关于状态转移方程
    // 其中 nums[j] < nums[i],即扫描 i 前面的桩,如果有比 i 小的话就使用状态转移方程 dp[i] = max(dp[i], dp[j] + 1),方程的意思是————如果前面某个桩(桩j)比 桩i 小,那么从那个桩踩上 桩i 的话自然就多了一步,我们拿这个踩完之后的步数 dp[j] + 1 跟当前存储的最大步数 dp[i] 比较一下,选个大的放进去。
    let inputArr = [];
    while ((line = await readline())) {
        inputArr.push(line);
        if (inputArr.length === 2) {
            // let inputArr = ["6", "2 5 1 5 4 5"];
            let n = +inputArr[0];
            let nums = inputArr[1].trim().split(" ").map(Number);
            let dp = new Array(n).fill(1);
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < i; j++) {
                    if (nums[j] < nums[i]) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                    }
                }
            }
            // console.log(dp)
            console.log(Math.max(...dp));
        }
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

在这里插入图片描述

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
    var arr = [];
    while ((line = await readline())) {
        arr.push(Number(line));
    }

    var fs = arr.filter((num) => num < 0);
    var zs = arr.filter((num) => num > 0);

    console.log(fs.length);
    if (zs.length > 0) {
        var n = zs.reduce((prev, cur) => prev + cur);
        var pj = n / zs.length;
        console.log(pj.toFixed(1));
    } else {
        console.log("0.0");
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

在这里插入图片描述

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()){
        let str = line.split('').reverse().join('')
        console.log(str)
    }
}()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

在这里插入图片描述

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())) {
        let num = +line;
        if (num > 0) {
            let n = Math.pow(num, 1 / 3);
            console.log(n.toFixed(1));
        } else {
            let n = Math.pow(-num, 1 / 3);
            console.log(-n.toFixed(1));
        }
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

在这里插入图片描述

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())) {
        let [x, y] = line.split(" ");
        x = x * 1;
        y = y * 1;
        for (let i = 1; i < y + 1; i++) {
            if ((x * i) % y === 0) return console.log(x * i);
        }
    }
})();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/857684
推荐阅读
相关标签
  

闽ICP备14008679号