题解 | 名字的漂亮度

名字的漂亮度

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)
    }
})();

全部评论

相关推荐

2024-11-08 00:11
复旦大学 深度学习
喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务