题解 | #名字的漂亮度#

名字的漂亮度

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

import java.util.Scanner;

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();

        for (int i = 0; i < n; i++) {
            String str = in.nextLine();
            str = str.toUpperCase();

            char[] charArray = str.toCharArray();
            int[] intArray = new int[26];
            for (char c : charArray) {
                intArray[c - 'A']++;
            }
            Arrays.sort(intArray);

            int num = 0;
            for (int j = intArray.length - 1; j >= 0; j--) {
                num += (26 - (intArray.length - 1 - j)) * intArray[j];
            }
            System.out.println(num);

        }
    }
}

全部评论

相关推荐

勇敢牛牛不怕困难,希望能过初筛
投递韶音科技等公司10个岗位
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
07-03 16:13
嘉应学院 Python
xiaolihuam...:很明显骗子,如果是hr直接约你面试了,哪用得着内推,如果是员工的话,你得多优秀,一线员工直接加你微信,
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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