Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string st = "[dw wd[ ww w]aa dwa dsf fre dz fd]";
- bool b = true;
- int x1 = 0;
- int x2 = 0;
- for (int i = 0; i < st.length(); ++i) {
- if (st[i] == '[') {
- x1++;
- cout << endl << "[ :" << i;
- if (x1 <= x2) {
- b = false;
- }
- } else if (st[i] == ']') {
- x2++;
- cout << endl << "] :" << i;
- }
- }
- if (x1 + x2 == 0) {
- cout << endl << "ERROR";
- } else if (b && x1==x2) {
- cout << endl << "there is a balance of parentheses";
- } else{
- cout << endl << "no balance brackets";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment