赞
踩
第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)
});
第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));
})();
第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)))
}()
第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);
})();
第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))
}()
第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())
}()
第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))
}()
第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]); // }
})();
第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('')))
}
}()
第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)
}
}()
第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)
}
}()
第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)
}
}()
第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)
}
}()
第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)
})
}()
第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)
}
}()
第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; } }
})();
第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); }
})();
第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))
}
}
}()
第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) }
})();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。