题解 | 名字的漂亮度

名字的漂亮度

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

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

int main() {
    int T;
    cin >> T;
    string str;
    while(cin >> str) {
        vector<int> alpha(26, 0);
        for(const char& c: str) {
            ++alpha[c - 'a'];
        }
        sort(alpha.begin(), alpha.end(), greater<int>());
        int beauty = 0, initial = 26;
        for(const int& a: alpha) {
            if(a) {
                beauty += a * (initial--);
            }
        }
        cout << beauty << endl;
    }
    return 0;
}

全部评论

相关推荐

07-03 16:02
门头沟学院 Java
今天面试,非常紧张,面试官问我springboot有哪些核心模块都答不上来了,真的对自己无语了!
程序员小白条:28届我勒个去,很多人面试都没机会
查看1道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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