-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1935.cpp
More file actions
38 lines (30 loc) · 822 Bytes
/
1935.cpp
File metadata and controls
38 lines (30 loc) · 822 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int N,val[26];
string s;
stack<double> st;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cout << fixed;
cout.precision(2);
cin >> N >> s;
for(int i=0 ; i<N ; i++) cin >> val[i];
for(int i=0 ; i<s.size() ; i++){
if(!st.empty() && (s[i] == '*'||s[i]=='/'||s[i]=='+' ||s[i]=='-')){
double b = st.top(); st.pop();
double a = st.top(); st.pop();
if(s[i] == '*') st.push(a*b);
else if(s[i] == '/') st.push(a/b);
else if(s[i] == '+') st.push(a+b);
else if(s[i] == '-') st.push(a-b);
}else {
st.push(val[s[i]-'A']);
}
}
cout << st.top();
}