You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
978 B
41 lines
978 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
string str;
|
||
|
getline(cin, str);
|
||
|
vector <char> sym;
|
||
|
vector <int> ans;
|
||
|
int a;
|
||
|
for (int i = 0; i < str.size(); i++){
|
||
|
if (str[i] != ' ') {
|
||
|
sym.push_back(str[i]);
|
||
|
}
|
||
|
}
|
||
|
for (int i = 0; i < sym.size(); i++) {
|
||
|
if ('0' <= sym[i] && sym[i] <= '9') {
|
||
|
ans.push_back(sym[i] - '0');
|
||
|
}
|
||
|
if (sym[i] == '+') {
|
||
|
a = ans[ans.size() - 1];
|
||
|
ans.pop_back();
|
||
|
ans[ans.size() - 1] += a;
|
||
|
}
|
||
|
if (sym[i] == '-') {
|
||
|
a = ans[ans.size() - 1];
|
||
|
ans.pop_back();
|
||
|
ans[ans.size() - 1] -= a;
|
||
|
}
|
||
|
if (sym[i] == '*') {
|
||
|
a = ans[ans.size() - 1];
|
||
|
ans.pop_back();
|
||
|
ans[ans.size() - 1] *= a;
|
||
|
}
|
||
|
}
|
||
|
for (int i = 0; i < ans.size(); i++)
|
||
|
cout << ans[i] << ' ';
|
||
|
|
||
|
return 0;
|
||
|
}
|