题解 | #名字的漂亮度#

名字的漂亮度

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

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        while(sc.hasNextInt()){
            int n = sc.nextInt();
            sc.nextLine();
            for(int i = 0; i < n; ++i){
                char[] cc = sc.nextLine().toCharArray();
                fun(cc);
            }
        }
    }

    public static void fun(char[] cc){
        HashMap<Character, Integer> map = new HashMap<>();
        for(char c : cc){
            map.put(c, map.getOrDefault(c,0) + 1);
        }
        int res = 0;
        int[] num = new int[map.keySet().size()];
        int index = 0;
        for(Character c : map.keySet()){
            num[index] = map.get(c);
            index++;
        }
        Arrays.sort(num);
        int mul = 26;
        for(int i = num.length - 1; i >= 0; --i){
            res += num[i] * mul;
            mul--;
        }
        System.out.println(res);
    }
}
全部评论

相关推荐

对空六翼:你真幸运,碰见这么好的人,不像我,秋招的时候被室友骗进cx了
实习好累,可以辞职全力准...
点赞 评论 收藏
分享
评论
15
3
分享

创作者周榜

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