From 7eee5a78005a9a569186d2c8b4b645a818ab9bf1 Mon Sep 17 00:00:00 2001 From: Stoycho Kyosev Date: Sun, 6 Oct 2024 07:04:44 -0400 Subject: Cleanup --- Seminar06/task02.cpp | 110 --------------------------------------------------- 1 file changed, 110 deletions(-) delete mode 100644 Seminar06/task02.cpp (limited to 'Seminar06/task02.cpp') diff --git a/Seminar06/task02.cpp b/Seminar06/task02.cpp deleted file mode 100644 index 5f8bf92..0000000 --- a/Seminar06/task02.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include -#include -#include - -bool isSymethric(const std::list& ll) { - auto start = ll.begin(); - auto end = --(ll.end()); - - while(start != end) { - if(*start != *end) - return false; - - ++start; - if(start == end) - break; - --end; - } - - return true; -} - -int evaluateExpr(char op, int fst, int snd) { - // assert(isOperator(op)); - - switch (op) { - case '+': - return (fst + snd); - break; - case '-': - return (fst - snd); - break; - case '*': - return (fst * snd); - break; - case '/': - return (snd / fst); - break; - } -} - -size_t evaluateQueue(std::queue q) { - std::stack nums; - - while(!q.empty()) { - if(isdigit(q.front())) { - int cDigit = q.front() - '0'; - q.pop(); - nums.push(cDigit); - } - else { - int fst = nums.top(); - nums.pop(); - int snd = nums.top(); - nums.pop(); - char op = q.front(); - q.pop(); - - nums.push(evaluateExpr(op, fst, snd)); - } - } - return nums.top(); -} - -bool solution(const std::list>& ll) { - std::list l; - - for(auto elem : ll) - l.push_back(evaluateQueue(elem)); - - return isSymethric(l); -} - -int main() { - std::list> test(5); - - auto it = test.begin(); - (*it).push('4'); - (*it).push('5'); - (*it).push('+'); - - ++it; - - (*it).push('1'); - (*it).push('6'); - (*it).push('+'); - (*it).push('7'); - (*it).push('*'); - ++it; - - (*it).push('8'); - ++it; - - (*it).push('1'); - (*it).push('7'); - (*it).push('7'); - (*it).push('*'); - (*it).push('*'); - - ++it; - - (*it).push('2'); - (*it).push('3'); - (*it).push('*'); - (*it).push('3'); - (*it).push('+'); - - - std::cout << solution(test); -} \ No newline at end of file -- cgit v1.3.1-26-gb76a