Codeforces Round #247 (Div. 2)(A)模拟

来源:互联网 发布:mysql解压版配置 编辑:程序博客网 时间:2024/05/30 04:13

A. Black Square
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.

In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.

You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?

Input

The first line contains four space-separated integers a1a2a3a4 (0 ≤ a1, a2, a3, a4 ≤ 104).

The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.

Output

Print a single integer — the total number of calories that Jury wastes.

Sample test(s)
input
1 2 3 4123214
output
13
input
1 5 3 211221
output
13




题意:每个格子对应消耗A[I]卡路里,给出字符串,分别对应每个格子,问一共消耗多少卡路里



题解:直接模拟就好



#include<iostream>#include<cstring>#define N int(1e+5)using namespace std;char s[N];int main(){#ifdef CDZSCfreopen("i.txt", "r", stdin);#endifint a[10];while (~scanf("%d", &a[1])){int ans = 0;for (int i = 2; i <= 4; i++)scanf("%d", a + i);scanf("%s", s);for (int i = 0; s[i]; i++)ans += a[s[i] - '0'];printf("%d\n", ans);}return 0;}






0 0
原创粉丝点击