diff options
| author | Andrew <saintruler@gmail.com> | 2021-02-10 23:56:03 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2021-02-10 23:56:03 +0400 |
| commit | e0857d37806f8da62d92f3462da14d6bd8aa8479 (patch) | |
| tree | c2ab59f6d361855f0c13bd8227ad261f4de9cb37 /structures/task25.cpp | |
| parent | a7a0646a34a1430568ec5cb22534f24c886d127b (diff) | |
Добавил решение 25 задачи
Diffstat (limited to 'structures/task25.cpp')
| -rw-r--r-- | structures/task25.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
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 <iostream> +#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; +} |