博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Codeforces Round #247 (Div. 2)] A. Black Square
阅读量:5371 次
发布时间:2019-06-15

本文共 2224 字,大约阅读时间需要 7 分钟。

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 4 123214
output
13
input
1 5 3 2 11221
output
13 题解:直接模拟。 代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 9 #define rep(i,a,b) for(i=(a);i<=(b);i++)10 #define red(i,a,b) for(i=(a);i>=(b);i--)11 #define sqr(x) ((x)*(x))12 #define clr(x,y) memset(x,y,sizeof(x))13 #define LL long long14 15 int i,j,n,m,sum,16 a[10];17 18 char b[110000];19 20 void pre()21 {22 clr(a,0);23 clr(b,'\0');24 sum=0;25 }26 27 int init()28 {29 rep(i,1,4)30 scanf("%d",&a[i]);31 getchar();32 scanf("%s",b);33 return 0;34 }35 36 int main()37 {38 int i,len;39 40 pre();41 init();42 len=strlen(b);43 len--;44 45 rep(i,0,len)46 sum+=a[b[i]-'0'];47 48 printf("%d\n",sum);49 50 return 0;51 }
 

 

 

转载于:https://www.cnblogs.com/sxiszero/p/3748503.html

你可能感兴趣的文章
php进行文件的强制下载
查看>>
每日python(6)
查看>>
Python正则表达式中的re.S的作用
查看>>
ubuntu15.10运行android studio出错unable to run mksdcard sdk tool
查看>>
HashMap面试知多少
查看>>
Effective C# 学习笔记(二十七)使你的类型可被序列化
查看>>
LDAP客户端配置
查看>>
(转)NAT原理与NAT穿越
查看>>
13.内存原理
查看>>
24.函数信号机制(本质上就是函数指针)
查看>>
The dependency `xxx` is not used in any concrete target.
查看>>
Bootstrap 中 下拉菜单和滚动监听插件(十一)(持续更新中。。。)
查看>>
团队-科学计算器-项目总结
查看>>
将DataTable中的数据绑定到TreeView中
查看>>
centos 7 问题集锦
查看>>
mysql小知识
查看>>
phpexcel
查看>>
python中最简单的多进程程序
查看>>
python---冒泡和短冒泡排序
查看>>
python---单向循环链表实现
查看>>