当前位置:网站首页>May day d-light

May day d-light

2022-07-07 23:39:00 Yuesi

subject

John believes that the perfection of a string is equal to the sum of the perfection of all the letters in it . The perfection of each letter can be assigned by you , Different letters have different degrees of perfection , Each corresponds to a 1-26 Integer between .

John doesn't care about the case of letters ( That is, the letters A and a The same degree of perfection ). Given a string , Output its maximum possible perfection . for example :dad, You can take 26 Assigned to d,25 Assigned to a, In this way, the perfection of the whole string is 77.

Input

Enter a string S(S The length of <= 10000),S There are no characters other than letters in the .

Output

It's up to you to 1-26 Assign to different letters , Make string S The most perfect , Output this perfection .

The sample input

dad

Sample output

77

#include<bits/stdc++.h>
using namespace std;
int cmp(int b1,int a1){
    
	return b1>a1;
}
int main(){
    
	string a;
	cin>>a;
	int l=a.length();
	for(int i=0;i<l;i++){
    
		a[i]=tolower(a[i]);
		// Convert all strings to lowercase letters  
	}
	int ans[150]={
    0};
	int k;
	for(int i=0;i<l;i++){
    
		k=(int)a[i];
		ans[k]++;// Record the number of occurrences of each letter  
	}	
	int num=0;
	int b[100]={
    0};
	for(int i=97;i<=122;i++){
    
		if(ans[i]!=0){
    
			b[num++]=ans[i];// Store the times in the array  
		}
	}
	sort(b,b+num,cmp);// Sort the number of times  
	int sum=0,k1=26;
	for(int i=0;i<num;i++){
    
		sum+=b[i]*k1;// Calculate assignment and maximum  
		k1--;
	}
	printf("%d\n",sum);
	return 0;
}

原网站

版权声明
本文为[Yuesi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130556375311.html