diff --git a/польский калькулятор.txt b/польский калькулятор.txt new file mode 100644 index 0000000..2ae907f --- /dev/null +++ b/польский калькулятор.txt @@ -0,0 +1,41 @@ +#include + +using namespace std; + +int main() +{ + string str; + getline(cin, str); + vector sym; + vector 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; +} \ No newline at end of file