当前位置:网站首页>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;
}
边栏推荐
- 通达信买基金安全吗?
- Open source hardware small project: anxinco esp-c3f control ws2812
- New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
- SAP 内存参数调优过程
- MySQL架构
- Slam interview summary
- USB (XIV) 2022-04-12
- 2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
- Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
- B_ QuRT_ User_ Guide(39)
猜你喜欢

The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way

Lm12 rolling heikin Ashi double K-line filter

SAP HR奖罚信息导出

Understand TCP's three handshakes and four waves with love

Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)

B_QuRT_User_Guide(36)

How to change the formula picture in the paper directly into the formula in word
postgis学习

The file format and extension of XLS do not match

C cat and dog
随机推荐
Spark 离线开发框架设计与实现
MySQL Architecture
2022 届的应届生都找到工作了吗?做自媒体可以吗?
C method question 2
POJ2392 SpaceElevator [DP]
The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
Ora-02437 failed to verify the primary key violation
USB (XIV) 2022-04-12
ASP. Net open web page
One of the anti climbing methods
平衡二叉樹【AVL樹】——插入、删除
USB (XVIII) 2022-04-17
Dependency injection
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
【汇总】看过的一些Panel与视频
B_QuRT_User_Guide(36)
Markdown
Explain
Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched
How can we make money by making video clips from our media?