View Code of Problem 3913

#include "stdlib.h"
#include "algorithm"
#include "iostream"
#include <cstdio>
#include "string"
#include <iomanip>
#include <map>
#include <set>
#include "math.h"
using namespace std;
map<int, bool> mp;
set<string> st;

int main() 
{
	int t; cin >> t; string str;
	while (t--)
	{
		int left = 0;
		cin >> str;
		int len = str.length();
		for (int i = 0; i < len; i++)
		{
			if (str[i] == '(')left++;
			if(str[i]==')')left--;
			if (left < 0)break;
		}
		if (left == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3913