题解 | 名字的漂亮度

名字的漂亮度

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

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

int main() {
    int n;
    while (cin >> n) {
        vector<string>str(n);
        for (int i = 0 ; i < n ; i++) {
            cin >> str[i];
            vector<int>counts(26, 0);
            for (int j = 0; j < str[i].size(); j++) {
                if (str[i][j] >= 'a' && str[i][j] <= 'z' ) {
                    counts[str[i][j] - 'a']++;
                } else if (str[i][j] >= 'A' && str[i][j] <= 'Z') {
                    counts[str[i][j] - 'A']++;
                }
            }
            sort(counts.begin(),counts.end());
            int ans = 0;
            int k = 26;
            for(int i = 25 ; i >= 0; i--){
                ans = (k)* counts[i] + ans;
                k--;
            }
            cout << ans <<endl;
        }
        
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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