题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int num = fzhinput.nextInt(); int beautfulscore; String zfc[] = new String [num]; fzhinput.nextLine(); for(int i=0;i<num;i++){ zfc[i] = fzhinput.nextLine(); String srzfc = zfc[i]; beautfulscore = maxwordscore(srzfc); System.out.println(beautfulscore); } } private static int maxwordscore(String srzfc){ int score=0,temp=26; int[] arr = new int[26]; if(srzfc==null || srzfc.length()==0){ return 0; } srzfc = srzfc.toLowerCase(); for(int i=0;i<srzfc.length();i++){ arr[srzfc.charAt(i)-'a']++; } Arrays.sort(arr); for(int i=arr.length-1; i>=0; i--){ if(arr[i]==0) break; score += arr[i]*temp; temp--; } return score; } }