Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool correcto(const string sec, int& n, int& p, int& c) {
  6.     if (n == sec.size()) {
  7.         if (p != 0 or c != 0) return false;
  8.         return true;
  9.     }
  10.     if (sec[n] == '(') correcto(sec,n+1,p+1,c);
  11.     else if (sec[n] == '[') correcto(sec,n+1,p,c+1);
  12.     else if (sec[n] == ')') correcto(sec,n+1,p-1,c);
  13.     else if (sec[n] == ']') correcto(sec,n+1,p,c-1);
  14. }
  15.  
  16. int main () {
  17.     string sec;
  18.     while (cin >> sec) {
  19.         int n=0, p=0, c=0;
  20.         if (correcto(sec, n, p, c)) cout << "si" << endl;
  21.         else cout << "no" << endl;
  22.     }      
  23. }
Add Comment
Please, Sign In to add comment