View Code of Problem 3913

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

Double click to view unformatted code.


Back to problem 3913