View Code of Problem 3913

#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<unordered_map>
#include<stack>

using namespace std;

int main()
{
	int T;
	cin >> T;

	for (int i = 0; i < T; i++) {

		string str;
		cin >> str;

		stack<char> stk;

		int flag = 0;
		for (int j = 0; j < str.size(); j++) {

			if (str[j] == '(')
				stk.push(str[i]);
			else {

				if (stk.size() > 0)
					stk.pop();
				else {

					flag = 1;
					break;
				}
			}
		}

		if (flag == 1 || stk.size() > 0)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
}

Double click to view unformatted code.


Back to problem 3913