codeforce A. Black Square

本文介绍了一款名为BlackSquare的游戏,玩家需点击屏幕上的黑块来消耗卡路里。文章详细解析了游戏规则,并提供了一个简单的Python代码,用于计算玩家在游戏过程中消耗的总卡路里。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Black Square

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

题目链接

http://codeforces.com/problemset/problem/431/A

原题

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.

Examples

input

1 2 3 4
123214

output

13

input

1 5 3 2
11221

output

13

题目大意

给你Jury下载了一个“Black Square”的游戏,就类似别踩白块儿吧,然后手机屏幕被分成4个垂直的条纹,Jury没点击一个条纹上的黑块都需要消耗一定的卡路里,然后第一行给出4个数字,代表点击这4个条纹分别需要的卡路里,第二行输入的是他点击的次序,只要把所有的消耗的卡路里都加起来就可以了

代码

while True:
	try:
		a,b,c,d=map(int,input().split())
		s=input()
		ans=0
		for i in s:
			if i=='1':
				ans+=a
			elif i=='2':
				ans+=b
			elif i=='3':
				ans+=c
			elif i=='4':
				ans+=d
		print(ans)
	except:
		break

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值