๋ฐ์ํ
https://codeforces.com/problemset/problem/431/A
์ฝ๋
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
int[] arr = new int[4];
for(int i=0; i<arr.length; i++)
arr[i] = Integer.parseInt(st.nextToken());
String str = bf.readLine();
int score = 0;
// ๋ฌธ์์ด์ ๊ฐ ๋ฌธ์๋ฅผ ์ธ๋ฑ์ค๋ก ํ๋ arr ๋ฐฐ์ด,
for(int i=0; i<str.length(); i++)
score += arr[str.charAt(i) - 49];
System.out.println(score);
bf.close();
}
}
ํ์ด
๋ฌธ์์ด์ด ์ฃผ์ด์ง ๋ ๊ฐ ๋ฌธ์์ด์ ๋ง๋ ๋ฐฐ์ด์ ๋ํ๋ฉด ๋จ.
๋ฐฐ์ด์ ์์์ 0์ด๋ฏ๋ก, ์๋ ์์คํค์ฝ๋ ๊ฐ์์ 48์ด ์๋ 49๋ฅผ ๋นผ์ผํ๋ค.
input
1 2 3 4
123214
arr[] = [1, 2, 3, 4]
score = arr[1] + arr[2] + arr[3] + arr[2] + arr[1] + arr[4] = 13
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค[Java] - ๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ (0) | 2020.03.07 |
---|---|
[๋ฐฑ์ค] 5052๋ฒ: ์ ํ๋ฒํธ ๋ชฉ๋ก (0) | 2020.03.07 |
ํ๋ก๊ทธ๋๋จธ์ค[Java] - ์์ฅ(ํด์) (0) | 2020.03.06 |
[๋ฐฑ์ค] 1062๋ฒ: ๊ฐ๋ฅด์นจ(์์ ํ์, ๋ฐฑํธ๋ํน) (0) | 2020.03.06 |
ํ๋ก๊ทธ๋๋จธ์ค[Java] - ์ ํ๋ฒํธ ๋ชฉ๋ก(ํด์) (0) | 2020.03.05 |
๋๊ธ