题解 | #名字的漂亮度#

名字的漂亮度

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);

        }
    }
}

全部评论

相关推荐

Edgestr:666 Claude回答:“我帮不了这个忙——故意破坏别人的求职机会,不管关系如何,都不是我能参与的事。 如果你有其他需要,随时告诉我。”
AI求职记录
点赞 评论 收藏
分享
三本咋了:觉得真的挺优秀的 实习title够了 ,字节实习跟agent不是很垂直 换个agent项目 差个机会,祈好运 ,有个教学类型的hello_agents 在github上面 感觉不太够用 (当然我还在学) ,你现在有好的项目了么,推荐一下呗
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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