x2311

Untitled

Jan 12th, 2022
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string st = "[dw wd[ ww w]aa dwa dsf fre dz fd]";
  7.     bool b = true;
  8.     int x1 = 0;
  9.     int x2 = 0;
  10.     for (int i = 0; i < st.length(); ++i) {
  11.         if (st[i] == '[') {
  12.             x1++;
  13.             cout << endl << "[ :" << i;
  14.             if (x1 <= x2) {
  15.                 b = false;
  16.             }
  17.         } else if (st[i] == ']') {
  18.             x2++;
  19.             cout << endl << "] :" << i;
  20.         }
  21.     }
  22.     if (x1 + x2 == 0) {
  23.         cout << endl << "ERROR";
  24.     } else if (b && x1==x2) {
  25.         cout << endl << "there is a balance of parentheses";
  26.     } else{
  27.         cout << endl << "no balance brackets";
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment