View Code of Problem 3913

#include <stdio.h>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;

int main() {
	int t;
	cin >> t;
	
	while (t--) {
		string str;
		stack<char> cun;
		int countz = 0;
		int county = 0;
		int flag = 1;
		cin >> str;
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == '(') {
				cun.push(str[i]);
				countz++;
			}
			else {
				county++;
				if (cun.size() <= 0) {
					flag = 0;
					break;
				}
				else {
					cun.pop();

				}
			}
		}
		if (countz == county && flag == 1 && cun.size() == 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}

	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3913