当前位置:网站首页>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;
}
边栏推荐
- StringUtils工具类
- B_ QuRT_ User_ Guide(36)
- 二叉排序树【BST】——创建、查找、删除、输出
- 伸展树(一) - 图文解析与C语言实现
- Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
- What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
- UE4_ Ue5 panoramic camera
- 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."
- Oracle statistics by time
- Take you hand in hand to build Eureka client with idea
猜你喜欢
Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
Explain
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
C simple question one
Deep understanding of MySQL lock and transaction isolation level
One week learning summary of STL Standard Template Library
SAP HR 社会工作经历 0023
0-1 knapsack problem
List. How to achieve ascending and descending sort() 2020.8.6
Live-Server使用
随机推荐
Summary of SQL single table query 2020.7.27
谷歌浏览器怎么登录及开启同步功能
SAP 内存参数调优过程
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
Slam interview summary
SAP HR reward and punishment information export
B_ QuRT_ User_ Guide(40)
B_QuRT_User_Guide(38)
SLAM面试总结
【7.5】15. Sum of three numbers
postgis学习
C number of words, plus ¥, longest word, average value
Illegal behavior analysis 1
[untitled]
伸展树(一) - 图文解析与C语言实现
One of the anti climbing methods
Have all the fresh students of 2022 found jobs? Is it OK to be we media?
Extended tree (I) - graphic analysis and C language implementation
8.31 Tencent interview
Markdown