View Code of Problem 3913

#include <iostream>
#include<stdio.h>
#include <string.h>
#include<cstring>
#include <math.h>
#include<algorithm>
#include <stack>
using namespace std;

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		stack<char> ss;
		string x;
		cin >> x;
		string zuo = "(";
		string you = ")";
		int flag = 1;
		for (int i = 0; i < x.length(); i++) {
			if (x[i] == '(') {
				ss.push(x[i]);
			}
			else
			{
				if (!ss.empty()) {
					ss.pop();
				}
				else
				{
					flag = 0;
					break;
				}
			}
		}
		if (flag==1&&ss.empty()) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3913