当前位置:网站首页>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;
}
边栏推荐
- Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
- 平衡二叉樹【AVL樹】——插入、删除
- 【7.5】15. Sum of three numbers
- Markdown
- New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
- Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
- POJ2392 SpaceElevator [DP]
- UE4_ Ue5 combined with Logitech handle (F710) use record
- KeePass realizes automatic input of web pages
- Have all the fresh students of 2022 found jobs? Is it OK to be we media?
猜你喜欢
Given an array, such as [7864, 284, 347, 7732, 8498], now you need to splice the numbers in the array to return the "largest possible number."
产业共融新势能,城链科技数字峰会厦门站成功举办
B_QuRT_User_Guide(37)
Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
Ora-02437 failed to verify the primary key violation
LM12丨Rolling Heikin Ashi二重K线滤波器
Understand TCP's three handshakes and four waves with love
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
UE4_ Ue5 combined with Logitech handle (F710) use record
随机推荐
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
Three questions TDM
How can we make money by making video clips from our media?
Extended tree (I) - graphic analysis and C language implementation
二叉排序树【BST】——创建、查找、删除、输出
Boost regex library source code compilation
Idea automatically generates serialVersionUID
Anxin vb01 offline voice module access intelligent curtain guidance
SAP HR 劳动合同信息 0016
C method question 1
IDEA 2021.3. X cracking
[untitled]
【7.4】25. K 个一组翻转链表
[experiment sharing] log in to Cisco devices through the console port
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)
Deep understanding of MySQL lock and transaction isolation level
B_QuRT_User_Guide(38)
Oracle string sorting