From 51d955fbdada4400c8efd504d637b4ece6fcee22 Mon Sep 17 00:00:00 2001 From: Stoycho Kyosev Date: Wed, 12 Oct 2022 15:42:41 +0300 Subject: add seminar02 --- Seminar02/task02.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Seminar02/task02.cpp (limited to 'Seminar02/task02.cpp') diff --git a/Seminar02/task02.cpp b/Seminar02/task02.cpp new file mode 100644 index 0000000..108e1f1 --- /dev/null +++ b/Seminar02/task02.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +bool isStringBalanced(const std::string& str) { + std::stack s; + + for (size_t i = 0; i < str.size(); i++) + { + if(str[i] == ')'){ + if(s.empty()) + return false; + s.pop(); + } + else { + s.push(str[i]); + } + } + return s.empty(); +} + +int main() { + std::cout << isStringBalanced("((()))((("); +} -- cgit v1.3.1-23-gd82d