当前位置:网站首页>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;
}
边栏推荐
- B_ QuRT_ User_ Guide(38)
- LM12丨Rolling Heikin Ashi二重K线滤波器
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
- FPGA basics catalog
- 2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
- Explain
- 【7.5】15. 三数之和
- One week learning summary of STL Standard Template Library
- [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
- 数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
猜你喜欢
[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
B_ QuRT_ User_ Guide(36)
Ora-02437 failed to verify the primary key violation
0-1背包问题
UE4_ Ue5 panoramic camera
0-1 knapsack problem
B_QuRT_User_Guide(38)
Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched
Three questions TDM
Open source hardware small project: anxinco esp-c3f control ws2812
随机推荐
Display the server hard disk image to the browser through Servlet
SAP HR 家庭成员信息
Oracle string sorting
B_QuRT_User_Guide(37)
MySQL Architecture
Illegal behavior analysis 1
【路径规划】使用垂距限值法与贝塞尔优化A星路径
USB (XVIII) 2022-04-17
Installing gradle
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
ASP. Net open web page
Take you hand in hand to build feign with idea
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
SAP HR social work experience 0023
Design and implementation of spark offline development framework
SAP memory parameter tuning process
UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)
B_QuRT_User_Guide(39)
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
Fibonacci number of dynamic programming