题解 | 名字的漂亮度

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
         Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
           String lineNumStr = scanner.nextLine();
           int lineNum = Integer.parseInt(lineNumStr);
           //String[] lines = new String[lineNum];
           for(int i = 0; i < lineNum; i ++)
           {
               //lines[i] = scanner.nextLine();
               String str = scanner.nextLine();
               int[] charNum = new int[26];
               for(int j = 0; j < str.length(); j ++)
               {
                   char ch = str.charAt(j);
                   charNum[ch - 'a'] ++;
               }
               Arrays.sort(charNum);
               int beautifulVal = 0;
               int startVal = 26;
               for(int k = charNum.length - 1; k >= 0; k --)
               {
                   if(charNum[k] != 0)
                   {
                       beautifulVal = beautifulVal + startVal * charNum[k];
                       startVal--;
                   }else{
                       break;
                   }
               }
               System.out.println(beautifulVal);
           }

        }
    }
}

全部评论

相关推荐

兄弟们,实习都是在接各种api,该怎么包装简历
仁者伍敌:感觉我自己做小项目也是各种api啊,我要怎么包装简历
点赞 评论 收藏
分享
Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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