A - Black Square
Problem Link: [Codeforces 431A##link##]
- [tab]
- C++
#include <iostream> #include <vector> #include <bits/stdc++.h> #define ll long long using namespace std; int main() { int a, b , c, d, som = 0; cin >> a >> b >> c >> d; string z; cin >> z; for(int i = 0; i < z.length();i++) { if(z[i] == '1') som+=a; if(z[i] == '2') som+=b; if(z[i] == '3') som+=c; if(z[i] == '4') som+=d; } cout << som; return 0; }
- Python3
c=list(map(int,input().split())) s=input() sumc=0 for i in range(len(s)): if s[i]=='1': sumc=sumc+c[0] if s[i]=='2': sumc=sumc+c[1] if s[i]=='3': sumc=sumc+c[2] if s[i]=='4': sumc=sumc+c[3] print(sumc)
- JAVA
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; // gravity flip problem public class App { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a1 = sc.nextInt(), calories = 0; int a2 = sc.nextInt(); int a3 = sc.nextInt(); int a4 = sc.nextInt(); sc.nextLine(); String[] values = sc.nextLine().split(""); for (String i : values) { switch (i) { case "1": calories += a1; break; case "2": calories += a2; break; case "3": calories += a3; break; case "4": calories += a4; break; } } System.out.println(calories); sc.close(); } }