0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 16:56:26 +00:00

P1449 后缀表达式

R41950224
This commit is contained in:
Baoshuo Ren 2020-11-15 16:09:16 +08:00 committed by Baoshuo Ren
parent 91e8a1f751
commit 199b564d3a
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

37
problem/P1449/P1449.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
stack<int> st;
char ch;
int a, b, t = 0;
while (cin >> ch, ch != '@') {
if (ch == '.') {
st.push(t);
t = 0;
}
else if('0' <= ch && ch <= '9') {
t *= 10;
t += ch - '0';
}
else {
b = st.top(); st.pop();
a = st.top(); st.pop();
if (ch == '+') {
st.push(a + b);
}
else if (ch == '-') {
st.push(a - b);
}
else if (ch == '*') {
st.push(a * b);
}
else if (ch == '/') {
st.push(a / b);
}
}
}
cout << st.top() << endl;
return 0;
}