当前位置:网站首页>May day d-light
May day d-light
2022-07-07 23:39:00 【Yuesi】
May day D - light
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;
}
边栏推荐
猜你喜欢

电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级

Lm12 rolling heikin Ashi double K-line filter

Live-Server使用

B_ QuRT_ User_ Guide(37)
![[experiment sharing] log in to Cisco devices through the console port](/img/e4/fc72ed57de74a0dd51c484a1c2f348.png)
[experiment sharing] log in to Cisco devices through the console port

PCB wiring rules of PCI Express interface

Ora-01741 and ora-01704
![Balanced binary tree [AVL tree] - insert, delete](/img/1f/cd38b7c6f00f2b3e85d4560181a9d2.png)
Balanced binary tree [AVL tree] - insert, delete

Take you hand in hand to build Eureka client with idea

B_ QuRT_ User_ Guide(36)
随机推荐
648. Word replacement
SLAM面试总结
C method question 2
Ora-01741 and ora-01704
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
HDU 4747 mex "recommended collection"
进度播报|广州地铁七号线全线29台盾构机全部完成始发
Interface
ESP at installation esp8266 and esp32 versions
Slam interview summary
JNI uses asan to check memory leaks
【汇总】看过的一些Panel与视频
2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
PCB wiring rules of PCI Express interface
做自媒体视频剪辑怎么赚钱呢?
Map operation execution process
C # exchange number, judge to pass the exam
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
Three questions TDM
Oracle string sorting