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 a1, a2, a3, a4 (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 4
123214
output
13
input
1 5 3 2
11221
output
13

题解:直接模拟。

代码:
 #include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<time.h> #define rep(i,a,b) for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset(x,y,sizeof(x))
#define LL long long int i,j,n,m,sum,
a[]; char b[]; void pre()
{
clr(a,);
clr(b,'\0');
sum=;
} int init()
{
rep(i,,)
scanf("%d",&a[i]);
getchar();
scanf("%s",b);
return ;
} int main()
{
int i,len; pre();
init();
len=strlen(b);
len--; rep(i,,len)
sum+=a[b[i]-'']; printf("%d\n",sum); return ;
}

 

[Codeforces Round #247 (Div. 2)] A. Black Square的更多相关文章

  1. Codeforces Round #247 (Div. 2) ABC

    Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431  代码均已投放:https://github.com/illuz/Wa ...

  2. Codeforces Round #599 (Div. 2) A. Maximum Square 水题

    A. Maximum Square Ujan decided to make a new wooden roof for the house. He has

  3. Codeforces Round #599 (Div. 2) A. Maximum Square

    Ujan decided to make a new wooden roof for the house. He has nn rectangular planks numbered from 11  ...

  4. Codeforces Round #247 (Div. 2) B - Shower Line

    模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

  5. Codeforces Round #249 (Div. 2) A. Black Square

    水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...

  6. Codeforces Round #247 (Div. 2)

    A.水题. 遍历字符串对所给的对应数字求和即可. B.简单题. 对5个编号全排列,然后计算每种情况的高兴度,取最大值. C.dp. 设dp[n][is]表示对于k-trees边和等于n时,如果is== ...

  7. Codeforces Round #247 (Div. 2) C题

    赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...

  8. Codeforces Round #247 (Div. 2) C. k-Tree (dp)

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

  9. Codeforces Round #247 (Div. 2) D. Random Task

    D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. cf D. Queue

    http://codeforces.com/contest/353/problem/D #include <cstdio> #include <cstring> #includ ...

  2. Qt下使用的静态链接库------ *.lib转化为mingw使用的.a格式的静态库

    使用MinGW附带的工具reimp.exe,该工具一般在MinGW in目录下,其readme文档在MinGWdoc eimp目录下, 方法很简单,比如: C:CodeBlocksMinGWlibdx ...

  3. android 无法生成R文件的原因剖析

    android 无法生成R文件 是件痛苦的事情,即使有时候你xml文件没有错误,他都无法生成.针对此问题,我总结以下几个方面的原因. 一.xml本身有错误 R.java这个文件是会自动生成的,但是如果 ...

  4. 【转】Date类学习总结(Calendar Date 字符串 相互转换 格式化)

    原文网址:http://www.blogjava.net/jerry-zhaoj/archive/2008/10/08/233228.html Date类学习总结 1.计算某一月份的最大天数 Cale ...

  5. python socket学习

    import socket localip=socket.gethostbyname(socket.gethostname()) print (localip) iplist=socket.getho ...

  6. jQuery 之$.proxy() 方法

    定义和用法 $.proxy 方法接受一个已有的函数,并返回一个带特定上下文的新的函数. 该方法通常用于向上下文指向不同对象的元素添加事件. 参数 描述 function 要被调用的已有的函数. con ...

  7. c语言学习之结构篇代码演示样例-输入n个同学的姓名,数学英语成绩,依照平均分从低到高排序并输出

    #include<stdio.h> void main(){ const int count = 5;//定义数量 struct student{ char name[80]; float ...

  8. python 安装 memcache

    方式一: python3 -m pip install python-memcached 方式二: pip3 install python-memcached 方式三: tar zxf python- ...

  9. 页面全部加载完毕和页面dom树加载完毕

    dom树加载完毕 $(document).ready()//原生写法document.ready = function (callback) {            ///兼容FF,Google   ...

  10. 未能的导入项目,请确认<Import>声明中的路径正确

    对于这样的错误,根据提示应该是项目的管理文件(.csproj)中有问题.找到对应的位置修改即可