codeforces-447B-DZY Loves Strings

简介:
DZY Loves Strings
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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?

Input
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.

Output
Print a single integer — the largest possible value of the resulting string DZY could get.

Sample test(s)
input
abc
3
1 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
output
41
Note
In the test sample DZY can obtain "abcbbc", value=1·1+2·2+3·2+4·2+5·2+6·2=41.






练练codeforces的评测
简单的字符串处理

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[2000];
int a[30];
int main()
{
    int i,m,n,sum=0,max;
    scanf("%s %d",s,&n);
    for(i=0;i<26;i++)
    scanf("%d",&a[i]);
    m=strlen(s);
    for(i=0;i<m;i++)
    sum+=(i+1)*a[s[i]-'a'];
    max=*max_element(a,a+26);
    i=m+1;
    while(n--)
    {
       sum+=i*max;
       i++;
    }
    printf("%d\n",sum);
    return 0;
}

相关文章
|
9月前
codeforces 318 A.Even Odds B.Sereja and Array
codeforces 318 A.Even Odds B.Sereja and Array
17 0
|
9月前
|
人工智能
codeforces 315 B.Sereja and Array
codeforces 315 B.Sereja and Array
21 0
|
9月前
codeforces 285C - Building Permutation
题目大意是有一个含n个数的数组,你可以通过+1或者-1的操作使得其中的数是1--n中的数,且没有重复的数。 既然是这样的题意,那么我就应该把原数组中的数尽量往他最接近1--n中的位置放,然后求差绝对值之和,但有多个数,怎么使他们和最小,这样就要对其进行排序了,直接按大小给它们安排好位置,然后计算。
22 0
|
9月前
codeforces 299 A. Ksusha and Array
题目就是让你找出一个数组中可以将这个数组中所有数整除的数,很明显,如果存在,这个数肯定是最小的一个。
29 0
|
2月前
|
C++ 容器
POJ3096—Surprising Strings
POJ3096—Surprising Strings
LeetCode 205. Isomorphic Strings
给定两个字符串 s 和 t,判断它们是否是同构的。 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的。 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序。两个字符不能映射到同一个字符上,但字符可以映射自己本身。
59 0
LeetCode 205. Isomorphic Strings
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
84 0
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
120 0