import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        Map<Character, Double> map = new HashMap<>();
        Stack<Double> stack = new Stack<>();
        char c = 'A';
        
        for(int i=0; i<n; i++) {
            map.put(c, Double.parseDouble(br.readLine()));
            c = (char)(c+1);
        }

        for(int i=0; i<s.length(); i++) {
            if(s.charAt(i)=='+') {
                double n1 = stack.pop();
                double n2 = stack.pop();
                stack.push(n1+n2);
            } else if(s.charAt(i)=='-') {
                double n1 = stack.pop();
                double n2 = stack.pop();
                stack.push(n2-n1);
            } else if(s.charAt(i)=='*') {
                double n1 = stack.pop();
                double n2 = stack.pop();
                stack.push(n1*n2);
            } else if(s.charAt(i)=='/') {
                double n1 = stack.pop();
                double n2 = stack.pop();
                stack.push(n2/n1);
            } else {
                stack.push(map.get(s.charAt(i)));
            }
        }
        
        System.out.printf("%.2f", stack.pop());
    } 
}

'Problem Solving > BOJ' 카테고리의 다른 글

[Silver 1] 6588번 골드바흐의 추측  (0) 2022.03.25
[Silver 4] 11656번 접미사 배열  (0) 2022.03.25
[Gold 3] 17299번 오등큰수  (0) 2022.03.22
[Gold 4] 17298번 오큰수  (0) 2022.03.22
[Silver 3] 10799번 쇠막대기  (0) 2022.03.22