题解 | #名字的漂亮度# c++ 数组

名字的漂亮度

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

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        int res = 0;
        string s;
        cin >> s;
        vector<int> count(26, 0);
        for(int i = 0; i < s.length(); ++i)
        {
            count[s[i] - 'a']++;
        }
        sort(count.begin(), count.end());
        for(int i = 25; i >= 0; --i)
        {
            res += (i + 1) * count[i]; 
        }
        cout << res << endl;
    }
    return 0;
}
全部评论
该牛油正在参与牛客写题解薅羊毛的活动,牛币,周边,京东卡超多奖品放送,活动进入倒计时!快来捡漏啦https://www.nowcoder.com/discuss/888949?source_id=profile_create_nctrack&channel=-1
点赞 回复 分享
发布于 2022-04-27 12:10

相关推荐

鲸鸿:实习协议不用管签多久,要走的时候提前三天说就可以了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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