Codeforces Round #FF (Div. 2/B)/Codeforces447B_ DZY Loves Strings(字符串处理)
来源:互联网 发布:组合软件 编辑:程序博客网 时间:2024/06/03 17:25
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
abc31 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
41
In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
水,好像还是写麻烦了。
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;char str[1010];int num[100],k,i,j,maxx=0;int main(){ cin>>str>>k; int l=strlen(str); for(i=0;i<26;i++) {cin>>num[i]; if(num[i]>maxx) maxx=num[i];} int sum=0; for(i=0;i<l;i++) { sum+=num[str[i]-'a']*(i+1); } for(j=i+1;k>0;j++,k--) { sum+=maxx*j; } cout<<sum<<endl; return 0;}
- Codeforces Round #FF (Div. 2/B)/Codeforces447B_ DZY Loves Strings(字符串处理)
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) 447B DZY Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) B.DYZ Loves Strings
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) Problem C DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C - DZY Loves Sequences
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- 揭秘QQ 安全密码框的原理
- lnmp -一键安装完成信息
- POJ 3450-Corporate Identity
- Hadoop URL数据读取操作
- iOS操作系统的层次架构和相关服务
- Codeforces Round #FF (Div. 2/B)/Codeforces447B_ DZY Loves Strings(字符串处理)
- 创建表(先判断是否有表)
- 数字图像处理-空间域增强(三)(图像的算数与逻辑运算)
- robotium(下)
- Dos命令删除添加新服务
- 闭包相关的实例
- ERROR: HHH000196: Error parsing XML (4) :
- OCP 1Z0 053 153
- [iOS diary]iOS在非主线程运行主线程的方法