Codeforces 447B DZY Loves Strings
来源:互联网 发布:固定循环编程注意? 编辑:程序博客网 时间:2024/05/21 18:00
题意:输入一个字符串,在这个字符串的后面增加k个字母,每个字母的价值已经给出,求这个字符串的最大价值。每个字符价值的计算是它的价值乘以它是第几个字符
解题思路:将26个字母的价值储存起来,找出价值最大的那个,然后在字符串后面加k个价值最大的字母
代码:
#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cstdio>#include <cmath>using namespace std;int main(){ string s; while(cin>>s) { int k; cin>>k; int a[30]; int ans=0; for(int i=0;i<26;i++) { cin>>a[i]; ans=max(a[i],ans); } int sum=0; for(int i=0;i<s.length();i++) { sum+=a[s[i]-'a']*(i+1); } for(int i=1;i<=k;i++) { sum+=ans*(s.length()+i); } cout<<sum<<endl; } return 0;}
阅读全文
0 0
- Codeforces 447B DZY Loves Strings
- codeforces-447B-DZY Loves Strings
- CodeForces 447B---DZY Loves Strings
- CodeForces 447B DZY Loves Strings
- CodeForces 447B DZY Loves Strings
- Codeforces 447B DZY Loves Strings
- 447B. DZY Loves Strings
- Codeforces Round #FF (Div. 2) 447B DZY Loves Strings
- B. DZY Loves Strings
- B. DZY Loves Strings
- CF 447B(DZY Loves Strings-贪心)
- CF 447B 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)B. DZY Loves Strings
- Codeforces Round #FF (Div. 2)B. DZY Loves Strings
- CodeForces 447-B. DZY Loves String
- 分梨
- HTML学习笔记二
- Struts2笔记
- 安装 Docker Machine
- 树链剖分模板
- Codeforces 447B DZY Loves Strings
- Alignment of Code
- PAT(Basic Level)_1011_A+B和C
- xgb原理及使用
- Centos下修改mysql的默认编码方式
- PAT(Basic Level)_1012_数字分类
- Ducci Sequence
- java中的迭代器模式
- oracle常用