Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar02 / task02.cpp
diff options
context:
space:
mode:
Commit51d955fbdada4400c8efd504d637b4ece6fcee22 (patch)
Author
 Stoycho Kyosev <stoycho.kk@gmail.com>
2022-10-12 15:42:41 +0300
Committer
 Stoycho Kyosev <stoycho.kk@gmail.com>
2022-10-12 15:42:41 +0300
Filese029d2772c32e4cce968faf6940f1b5bde46f0cc /Seminar02/task02.cpp
Data-structures-and-algorithms-51d955fbdada4400c8efd504d637b4ece6fcee22.tar
Data-structures-and-algorithms-51d955fbdada4400c8efd504d637b4ece6fcee22.tar.gz
Data-structures-and-algorithms-51d955fbdada4400c8efd504d637b4ece6fcee22.zip
Parentfd8930b9c939f3b234b7fe661f329004a931b79c (diff)
add seminar02
1 files changed, 24 insertions, 0 deletions
-rw-r--r--Seminar02/task02.cpp24
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<iostream>
+#include<stack>
+#include<string>
+
+bool isStringBalanced(const std::string& str) {
+ std::stack<char> 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("((()))(((");
+}