题解 | #名字的漂亮度#

名字的漂亮度

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.next());
        }
        for (int i = 0; i < list.size(); i++) {
            function(list.get(i));
        }
    }

    public static void function(String str) {
        HashMap<String, Integer> hm = new HashMap<>();
        for (String s : str.split("")) {
            hm.put(s, hm.getOrDefault(s, 0) + 1);
        }
        ArrayList<Integer> F = new ArrayList<>();
        for (String s : hm.keySet()) {
            F.add(hm.get(s));
        }
        F.sort((Integer o1, Integer o2) -> {return o2 - o1;});
        int result = 0;
        int mul = 26;
        for (int j = 0; j <= F.size() - 1; j++) {
            result += F.get(j) * mul;
            mul--;
        }
        System.out.println(result);
    }
}

全部评论

相关推荐

牛客773130651号:巨佬,简历模板换成上下的,左右的很烦,hr看着不爽。。。科大随便乱杀,建议能保研就保研,不行也得考一下 ,985硕去干算法,比开发强多了。开发许多双非都能搞,学历优势用不上,算法有门槛
点赞 评论 收藏
分享
06-06 03:40
已编辑
电子科技大学 Java
在秋招的小白菜很想养修勾:一眼 苍穹外卖+谷粒商城,项目换一换吧,可以找一些付费知识星球博主带带,避免烂大街。多投投大厂,背背八股,你这学历乱杀了,等实习经验到位,到时候大厂闭眼选
投递美团等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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