Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stack>
- #include <string>
- using namespace std;
- int main() {
- int n, i, j;
- string str;
- stack<int> s;
- int count;
- cin >> n;
- for (i = 0; i < n; i++) {
- cin >> str;
- count = 0;
- for (j = 0; j <= str.size(); j++) {
- if (str[j] == '(') {
- s.push(str[j]);
- count++;
- }
- else if (str[j] == ')') {
- if (s.size() != 0) {
- s.pop();
- count--;
- }
- else {
- count++;
- }
- }
- }
- if (count == 0) {
- cout << "YES" << endl;
- }
- else {
- cout << "NO" << endl;
- }
- for (j = 0; j <= str.size(); j++) {
- if (s.size() != 0) {
- s.pop();
- }
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment