The name of the beautiful degree =26* the number of letters +25* the number of letters followed by the number of +24* letters followed by the second (ignoring the case) +....+1* the smallest occurrence.
Input: integer n,n a string
Output: n string of beautiful degrees
For example:
Input 1 A
Output 26
C
#include <iostream>#include <string>#include <cctype>#include <algorithm>using namespace STD;BOOLcmpintAintb) {returnA>b;}intMeili (Const string&STR) {inta[ -]={0};intlen=0, POS; for(intI=0; I<str.size (); i++) {if(Isupper(Str[i])) pos=str[i]- $;Elsepos=str[i]- the; a[pos]++; } sort (a,a+ -, CMP); for(i=0; a[i]!=0; i++) {len+= ( --i) *a[i]; }returnLen;}intMainintargcChar*argv[]) {intNCin>>n;int*len=New int[n];stringStr for(intI=0; i<n;i++) {Cin>>str; Len[i]=meili (str); } for(i=0; i<n;i++)cout<<len[i]<<endl;Delete[]len;return 0;}
Java
ImportJava.util.Arrays;ImportJava.util.Scanner; Public class Namemei { Public int Meili(String str) {int[] A =New int[ -];//Default value is 0 intLen =0, POS; for(inti =0; I < str.length (); i++) {if(Character.isuppercase (Str.charat (i))) pos = Str.charat (i)- $;Elsepos = Str.charat (i)- the; a[pos]++; } arrays.sort (a);//From small to large for(inti = -; A[i]! =0; i--) len + = (i+1) * A[i];returnLen } Public Static void Main(string[] args) {Namemei nm =NewNamemei (); Scanner s =NewScanner (system.in);intn = s.nextint ();int[] len =New int[n]; String str; for(inti =0; I < n; i++) {Scanner SS =NewScanner (system.in); str = Ss.nextline (); Len[i] = Nm.meili (str); } for(inti =0; I < n; i++) System.out.println (Len[i]); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Huawei Machine Test-The beauty of the name