题解 | #名字的漂亮度#

名字的漂亮度

https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3?tpId=37&tqId=21268&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        int l = str.length();
        int a[26] = {0};
        for (int j = 0; j < l; j++) {
            if (isalpha(str[j])) {
                a[str[j] - 'a'] ++;
            }
        }
        sort(a, a + 26, greater<int>());
        int sum = 0;
        int point = 26;
        for (int j = 0; j < 26; j++) {
            sum += a[j] * point;
            point --;
        }
        cout << sum << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

小牛炒肉:好大的官威居然不是什么官
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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