Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar02 / task03.cpp
diff options
context:
space:
mode:
Commit7eee5a78005a9a569186d2c8b4b645a818ab9bf1 (patch)
Author
 Stoycho Kyosev <skyosev@192.168.100.17>
2024-10-06 07:04:44 -0400
Committer
 Stoycho Kyosev <skyosev@192.168.100.17>
2024-10-06 07:04:44 -0400
Files84594e0af29cefa5aae76ace5f8eb81484400e31 /Seminar02/task03.cpp
Data-structures-and-algorithms-7eee5a78005a9a569186d2c8b4b645a818ab9bf1.tar
Data-structures-and-algorithms-7eee5a78005a9a569186d2c8b4b645a818ab9bf1.tar.gz
Data-structures-and-algorithms-7eee5a78005a9a569186d2c8b4b645a818ab9bf1.zip
Parent0841635826cb03c0e74cd75ec3c97c4c3b594d8b (diff)
Cleanup
1 files changed, 0 insertions, 59 deletions
-rw-r--r--Seminar02/task03.cpp59
diff --git a/Seminar02/task03.cpp b/Seminar02/task03.cpp
deleted file mode 100644
index 1c7a095..0000000
--- a/Seminar02/task03.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#include<iostream>
-#include<stack>
-#include<string>
-#include<cassert>
-
-bool isOperation(char c) {
- return (c == '+') || (c == '-') || (c == '*') || (c == '/');
-}
-
-bool isDigit(char c) {
- return c >= '0' && c <= '9';
-}
-
-int eval(int fst, int snd, char op) {
- assert(isOperation(op));
-
- switch (op) {
- case '+':
- return fst + snd;
- case '-':
- return fst - snd;
- case '*':
- return fst * snd;
- case '/':
- return fst / snd;
- }
-}
-
-int RPN(const std::string& str) {
- std::stack<int> numbers;
-
- for (size_t i = 0; i < str.size(); i++) {
- if(isOperation(str[i])) {
- int snd = numbers.top();
- numbers.pop();
-
- int fst = numbers.top();
- numbers.pop();
-
- numbers.push(eval(fst, snd, str[i]));
- }
- else if(str[i] != ' ') {
- int number = 0;
- while(i < str.size() && isDigit(str[i])) {
- number *= 10;
- number += str[i] - '0';
- i++;
- }
- i--;
- numbers.push(number);
- }
- }
-
- return numbers.top();
-}
-
-int main() {
- std::cout << RPN("9 3 4 * - 2 5 * -");
-} \ No newline at end of file