当前位置:网站首页>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;
}
边栏推荐
- 【实验分享】通过Console口登录到Cisco设备
- The for loop realizes 1-100 addition and eliminates the 4-digit tail number
- MySQL架构
- 移动端异构运算技术 - GPU OpenCL 编程(基础篇)
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
- 2022第六季完美童模陕西总决赛圆满落幕
- Oracle string sorting
- ASP. Net query implementation
- How to change the formula picture in the paper directly into the formula in word
- Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
猜你喜欢
How to change the formula picture in the paper directly into the formula in word
postgis学习
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
ping报错:未知的名称或服务
C cat and dog
Live-Server使用
平衡二叉树【AVL树】——插入、删除
LM12丨Rolling Heikin Ashi二重K线滤波器
Take you hand in hand to build Eureka client with idea
随机推荐
Display the server hard disk image to the browser through Servlet
C number of words, plus ¥, longest word, average value
ASP. Net open web page
2022第六季完美童模陕西总决赛圆满落幕
谷歌浏览器怎么登录及开启同步功能
Live-Server使用
List. How to achieve ascending and descending sort() 2020.8.6
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
HDU 4747 mex "recommended collection"
【7.5】15. 三数之和
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
数据库面试题+解析
二叉排序树【BST】——创建、查找、删除、输出
Installing gradle
Boost regex library source code compilation
USB (XVII) 2022-04-15
Three questions TDM
Svn relocation