题解 | #名字的漂亮度#

名字的漂亮度

https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3

#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

bool cmp (int &a, int &b){
    return a >b;
}
int main() {
    int n ;
    cin>>n;
    while (n--){
        string str;
        cin >>str;
        unordered_map<char, int> map;
        for (auto ch : str)
            map[ch]++;
        vector<int> vec;
        for (auto it : map)
            vec.push_back(it.second);
        sort(vec.begin(), vec.end(), cmp);
        int result = 0, index = 26;
        for (auto x : vec){
            result += x * index;
            index--;
        }
        cout << result<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务