From e0857d37806f8da62d92f3462da14d6bd8aa8479 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 10 Feb 2021 23:56:03 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=80?= =?UTF-8?q?=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=2025=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structures/task25.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 structures/task25.cpp (limited to 'structures/task25.cpp') diff --git a/structures/task25.cpp b/structures/task25.cpp new file mode 100644 index 0000000..fde664c --- /dev/null +++ b/structures/task25.cpp @@ -0,0 +1,51 @@ +#include +#include "stack.h" + +using namespace std; + +int main() +{ + int n; + cout << "n = "; + cin >> n; + + stack *s = NULL; + char* buf = new char[32]; + for (int i = 0; i < n; i++) + { + cin >> buf; + if ('0' <= buf[0] && buf[0] <= '9') + { + int i = atoi(buf); + push(s, i); + } + else + { + switch (buf[0]) + { + case '+': { + int o1 = pop(s); + int o2 = pop(s); + push(s, o2 + o1); + } break; + + case '-': { + int o1 = pop(s); + int o2 = pop(s); + push(s, o2 - o1); + } break; + + case '*': { + int o1 = pop(s); + int o2 = pop(s); + push(s, o2 * o1); + } break; + } + } + } + + int result = pop(s); + cout << "Result = " << result << endl; + + return 0; +} -- cgit v1.2.3