题解 | #名字的漂亮度#

名字的漂亮度

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

#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
using namespace std;

int main(){
    int n ;
    cin >> n;
    while(n--){
        vector<int>bucket(26,0);
        vector<int>res;
        int ans = 0;
        string str;
        cin >> str;
        for(char c : str){
            int tmp = c - 'a';
            bucket[tmp]++;
        }

        for(int i = 0 ; i < 26; i++){
            if(bucket[i])
                res.push_back(bucket[i]);
        }

        sort(res.begin(),res.end());
        for(int i = 26; i >= 0 ; i--){
            if(res.empty())
                break;
            int num = res.back();
            ans += num * i ;
            res.pop_back();
        }
        cout << ans << endl;
    }
}
全部评论

相关推荐

待现的未见之事:起码第一句要把自己的优势说出来吧。比如什么xx本27届学生,随时到岗....
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务