-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (43 loc) · 1.04 KB
/
main.cpp
File metadata and controls
53 lines (43 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stack>
//https://www.acmicpc.net/problem/1935
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
int* value = new int[n+1];
string model;
cin >> model;
stack<double> stack;
for(int i=0; i<n; i++){
cin >> value[i];
}
for(char i : model){
if(i >= 'A' && i <= 'Z'){
stack.push(value[i - 'A']);
}
else{
double num1 = stack.top();
stack.pop();
double num2 = stack.top();
stack.pop();
if(i == '*'){
stack.push(num2 * num1);
}
else if(i == '/'){
stack.push(num2 / num1);
}
else if(i == '-'){
stack.push(num2 - num1);
}
else if(i == '+'){
stack.push(num2 + num1);
}
}
}
//소수점 둘째 자리 출력
cout << fixed;
cout.precision(2);
cout << stack.top() << endl;
}