[백준] 9012 괄호

0

백준

목록 보기
152/271
post-thumbnail
post-custom-banner

[백준] 9012 괄호

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		string str;
		cin >> str;

		stack<char> st;
		for (int i = 0; i < str.length(); ++i) {
			if (st.empty()) {
				st.push(str[i]);
				continue;
			}
			
			if (st.top() == '(' && str[i] == ')') st.pop();
			else st.push(str[i]);
		}

		if (st.empty()) cout << "YES\n";
		else cout << "NO\n";
	}

	return 0;
}

profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글