题解 | 名字的漂亮度
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
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 quanlity = await readline(); while ((line = await readline())) { culculate(line); } //计算漂亮度 function culculate(str) { const charMap = new Map(); const valueMap = new Map(); for (let i = 0; i < str.length; i++) { let chart = str[i]; charMap.set(chart, (charMap.get(chart) || 0) + 1); } let valueArr = Array.from(charMap.values()).sort((a,b) => b -a) let res = 0 const length = 26 - valueArr.length let i = 26 for(let item of valueArr) { res += item * i i-- } console.log(res) } })();