赞
踩
//计算字符串最后一个单词的长度,单词以空格隔开,字符串长度小于5000。 var input = readline(); function test(text) { return text.split(' ')[text.split(' ').length - 1].length } console.log(test(input)); // 写出一个程序,接受一个由字母、数字和空格组成的字符串,和一个字符,然后输出输入字符串中该字符的出现次数。(不区分大小写字母) var input = readline().toLowerCase(); var key = readline().toLowerCase(); function findTime(input, key) { let count = 0; input.split('').forEach(data => { if (data === key) { count++ } }) return count } console.log(findTime(input, key)) // 明明的随机数 var number = readline() var list = {}; function sortNumber(a, b) { return a - b } function find(number, index) { list[index] = []; for (let i = 0; i < number; i++) { list[index].push(readline()) } let time = readline(); if (time) { index++ find(time, index) } else { return } } find(number, 0); Object.keys(list).forEach(key => { list[key] = [...new Set(list[key])].sort(sortNumber) list[key].forEach(value => { console.log(value) }) }) // 字符串分隔 var str; while (str = readline()) { getStr(str) } function getStr(str) { let resStr; if (str.length == 8) { resStr = str; console.log(resStr) } else if (str.length < 8) { resStr = str.padEnd(8, '0'); console.log(resStr) } else { let restStr = str.slice(8); resStr = str.slice(0, 8); console.log(resStr) getStr(restStr); } } // 进制转换 while (str = readline()) { console.log(parseInt(str, 16)) } // 质数因子 var num = parseInt(readline()) var list = []; var i = 2; while (i <= num && i * i <= num) { if (num % i === 0) { list.push(i) num /= i i = 2 } else { i++ } } if (num != 1) { list.push(num) } console.log(list.join(' ')) // 取近似值 var num = parseFloat(readline()) console.log(num.toFixed()) // 合并表记录 var num = parseInt(readline()) let i = 0; let c = new Map() while (i < num) { let a = readline().split(' ') if (c.has(a[0])) { c.set(a[0], parseInt(c.get(a[0])) + parseInt(a[1])) } else { c.set(a[0], a[1]) } i++ } let data = Array.from(c) data.sort((a, b) => { return a[0] - b[0] }) data.forEach((value) => { console.log(`${value[0]} ${value[1]}`) }) //提取不重复的整数 console.log(parseInt([...new Set(readline().toString().split('').reverse())].join(''))) //字符个数统计 console.log([...new Set(readline())].map(data => { if (data.charCodeAt < 0 || data.charCodeAt > 127) return return data }).length) //数字颠倒 console.log(readline().split('').reverse().join('')) //字符串反转 console.log(readline().split('').reverse().join('')) //句子逆序 console.log(readline().split(' ').reverse().join(' ')) //字符串排序 let a = readline(); let i = 0 let list = []; while (i < a) { list.push(readline()) i++ } list.sort() list.forEach(data => console.log(data)) //求int型正整数在内存中存储时1的个数 let count = 0; parseInt(readline()).toString(2).split('').forEach(data => { if (data === '1') { count++ } }) console.log(count) while (str1 = readline()) { const str2 = readline(); console.log(minDistance(str1.split(''), str2.split(''))); } function minDistance(str1, str2) { let n = str1.length; let m = str2.length; if (n * m === 0) return m + n; if (str1 === str2) return 0; let number = 0; let length = n - m ? n : m; let i = 0; for (i; i < length; i++) { if (str1[i] && str2[i]) { if (str1[i] !== str2[i]) { number++ } } else if ((str1[i] && !str2[i]) || (str2[i] && !str1[i])) { number++ } } return number } console.log(minDistance('abcde', 'bcdef')) // 字符统计 var str; while (str = readline()) { findAll(str.split('')) } function findAll(str) { let map = new Map(); str.forEach(data => { if (map.has(data)) { map.set(data, map.get(data) + 1) } else { map.set(data, 1) } }) let data = Array.from(map) data.sort((a, b) => { if (a[1] === b[1]) { return a[0].charCodeAt() - b[0].charCodeAt() } else { return b[1] - a[1] } }) let string = '' data.forEach(value => { string = string + value[0] }) console.log(string) } var str while (str = readline()) { test(readline().split('')) } function test(list) { let data = []; list.forEach((value, i) => { let text = value; let dataList = list.slice(i + 1) dataList.sort((a, b) => { return parseInt(a) - parseInt(b) }).filter(value => { return parseInt(text) < parseInt(value) }) console.log(dataList) dataList = [...new Set(dataList)]. data.push(dataList.length + 1) }) data.sort() return data[data.length - 1] } console.log(test(('186 13 322 264 328 110').split(' ')))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。