Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags more
Archives
Today
Total
관리 메뉴

난 정말 최고야 멋있어

[BOJ] 괄호 본문

카테고리 없음

[BOJ] 괄호

n00bh4cker 2020. 1. 8. 21:19
#include <iostream>
#include <string>
#include <stack>
using namespace std;

void checkVPS(string& ps)
{
	stack<int> s;
	for (auto& i : ps)
	{
		if (i == '(')
			s.push(0);
		if (i == ')')
		{
			if (s.empty())
			{
				cout << "NO" << endl;
				return;
			}
			s.pop();
		}
	}
	if (s.empty())
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
int main()
{
	int T;
	string PS;
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		cin >> PS;
		checkVPS(PS);
	}
}