题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let inputs = []; let inputTimes = 0 rl.on("line", function (line) { inputs.push(line.trim()); if(inputTimes == Number(inputs[0])){ let arr = inputs.splice(1,inputs.length-1) arr.forEach(item=>{ max(item) }) }else{ inputTimes++ } function max(str){ let numArr = [] let tempArr = [...new Set(str.split(''))] for(let i = 0;i<tempArr.length;i++){ count = 0 for(let j = 0; j<str.length;j++){ if(tempArr[i] ==str[j]){ count++ } } numArr.push(count) } let sum = 0 numArr.sort((a,b)=>b-a).forEach((item,i)=>{ sum += item*(26-i) }) console.log(sum) } });