Huawei Machine Test-the name of the beautiful degree

Source: Internet
Author: User

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&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.