Codeforces Round #247(Div. 2) A. Black Square 水題
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
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?
InputThe first line contains four space-separated integers
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
Print a single integer — the total number of calories that Jury wastes.
Examples input1 2 3 4 123214output
13input
1 5 3 2 11221output
13
題意:
手機螢幕分成4塊,點選每塊需要消耗的卡路里給定,然後給定點選列表,求出總的卡路里。
題解:
水題
/****************
*PID:431a div2
*Auth:Jonariguez
*****************
*/
#define lson k*2,l,m
#define rson k*2+1,m+1,r
#define rep(i,s,e) for(i=(s);i<=(e);i++)
#define For(j,s,e) For(j=(s);j<(e);j++)
#define sc(x) scanf("%d",&x)
#define In(x) scanf("%I64d",&x)
#define pf(x) printf("%d",x)
#define pfn(x) printf("%d\n",(x))
#define Pf(x) printf("%I64d",(x))
#define Pfn(x) printf("%I64d\n",(x))
#define Pc printf(" ")
#define PY puts("YES")
#define PN puts("NO")
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef int Ll;
Ll quick_pow(Ll a,Ll b,Ll MOD){a%=MOD;Ll res=1;while(b){if(b&1)res=(res*a)%MOD;b/=2;a=(a*a)%MOD;}return res;}
const int maxn=100000+10;
int a[maxn];
char str[maxn];
int main()
{
int i,j,n,m;
for(i=1;i<=4;i++)
sc(a[i]);
int sum=0;
scanf("%s",str+1);
n=strlen(str+1);
for(i=1;i<=n;i++)
sum+=a[str[i]-'0'];
printf("%d\n",sum);
return 0;
}