美文网首页
HWOJ名字的漂亮度

HWOJ名字的漂亮度

作者: Yuu_CX | 来源:发表于2017-02-19 12:37 被阅读0次
    import java.util.*;
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int n1 = sc.nextInt();
            String[] str = new String[n1];
            for(int i=0 ; i< n1 ; i++){
                char[] ch = new char[26];
                str[i] = sc.next().toLowerCase();
                for(int j=0;j<str[i].length();j++){
                    ch[str[i].charAt(j)-'a']++;
                }
                Arrays.sort(ch);
                System.out.println(getValue(ch));
            }
        }
        public static int getValue(char[] c){
            int res = 0;
            for(int k=c.length-1;k>=0;k--){
                res += c[k]*(26-c.length+1+k);
            }
            return res;
        }
    }
    

    相关文章

      网友评论

          本文标题:HWOJ名字的漂亮度

          本文链接:https://www.haomeiwen.com/subject/yhhjwttx.html