0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 19:56:28 +00:00
OI-codes/Luogu/P1449/P1449.cpp

35 lines
764 B
C++
Raw Normal View History

2020-11-15 08:09:16 +00:00
#include <bits/stdc++.h>
using namespace std;
int main() {
stack<int> st;
2021-11-19 09:01:13 +00:00
char ch;
int a, b, t = 0;
2020-11-15 08:09:16 +00:00
while (cin >> ch, ch != '@') {
if (ch == '.') {
st.push(t);
t = 0;
2021-11-19 09:01:13 +00:00
} else if ('0' <= ch && ch <= '9') {
2020-11-15 08:09:16 +00:00
t *= 10;
t += ch - '0';
2021-11-19 09:01:13 +00:00
} else {
b = st.top();
st.pop();
a = st.top();
st.pop();
2020-11-15 08:09:16 +00:00
if (ch == '+') {
st.push(a + b);
2021-11-19 09:01:13 +00:00
} else if (ch == '-') {
2020-11-15 08:09:16 +00:00
st.push(a - b);
2021-11-19 09:01:13 +00:00
} else if (ch == '*') {
2020-11-15 08:09:16 +00:00
st.push(a * b);
2021-11-19 09:01:13 +00:00
} else if (ch == '/') {
2020-11-15 08:09:16 +00:00
st.push(a / b);
}
}
}
cout << st.top() << endl;
return 0;
}