Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- string s = "()()(())((()))"; // open = 1
- int open = 0;
- int n = (int) s.size();
- //~ bool f = true;
- for (int i = 0; i < n; ++i) {
- if (s[i] == '(') {
- ++open;
- } else {
- --open;
- }
- if (open < 0) {
- //close bracket beshi ache
- cout << "INVALID\n";
- return 0;
- }
- }
- //ekhane asar mane hocche open < 0 execute hoy ni
- if (open > 0) {
- //open bracket beshi ache
- cout << "INVALID\n";
- } else {
- cout << "VALID\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement