Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									할껀하고놀자
[백준] 9012번 괄호 본문
728x90
    
    
  #include<iostream>
#include<stack>
using namespace std;
bool check(string s) {
	stack<char> st;
	for (int j = 0; j < s.length(); j++) {
		if (s[j] == '(') {
			st.push(s[j]);
		}
		else {
			if (st.empty()) {
				return false;
			}
			char c = st.top();
			if (c == '(') {
				st.pop();
			}
			else {
				return false;
			}
		}
	}
	if (st.empty()) {
		return true;
	}
	else {
		return false;
	}
}
int main() {
	int tc;
	cin >> tc;
	for (int i = 0; i < tc; i++) {
		string s;
		cin >> s;
		bool b = check(s);
		if (b) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		
	}
	return 0;
}
'[IT] > 백준' 카테고리의 다른 글
| [백준] 10951 A+B-4 (테스트케이스가 안주어졌을 때) (0) | 2019.09.09 | 
|---|---|
| [백준] 1786번 찾기 (KMP 알고리즘) (0) | 2019.09.09 | 
| [백준] 17143번 낚시왕 (0) | 2019.06.11 | 
| [백준] 11365번 !밀비 급일 (0) | 2019.06.10 | 
| [백준] 10773번 제로 (0) | 2019.06.10 | 
			  Comments