Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- stack <char> stk;
- string a;
- cin >> a;
- if(a[0] == '(') {
- for (int i = 0; i < a.length(); i++) {
- if (a[i] == '(') {
- stk.push(a[i]);
- } else if (a[i] == ')') {
- stk.pop();
- }
- }
- } else if(a[0] == ')') {
- return false;
- }
- if(stk.size() == 0) {
- cout << "Valid" << endl;
- } else {
- cout << "Invalid" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement