Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- bool correcto(const string sec, int& n, int& p, int& c) {
- if (n == sec.size()) {
- if (p != 0 or c != 0) return false;
- return true;
- }
- if (sec[n] == '(') correcto(sec,n+1,p+1,c);
- else if (sec[n] == '[') correcto(sec,n+1,p,c+1);
- else if (sec[n] == ')') correcto(sec,n+1,p-1,c);
- else if (sec[n] == ']') correcto(sec,n+1,p,c-1);
- }
- int main () {
- string sec;
- while (cin >> sec) {
- int n=0, p=0, c=0;
- if (correcto(sec, n, p, c)) cout << "si" << endl;
- else cout << "no" << endl;
- }
- }
Add Comment
Please, Sign In to add comment