dh-winternagi 님의 블로그
(9012) 괄호 본문
https://www.acmicpc.net/problem/9012
단계별로 풀어보기
16단계(스택, 큐, 덱 1) 3번째

#include <iostream>
#include <stack>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while(T--){
stack<bool> st;
string s;
bool check= true;
cin >> s;
for(char c:s){
if(c=='('){
st.push(true);
}else{
if(st.empty()){
check= false;
break;
}else{
st.pop();
}
}
}
cout << (check&&st.empty() ? "YES\n" : "NO\n");
}
return 0;
}'백준 (C++) > Solve' 카테고리의 다른 글
| (12789) 도키도키 간식드리미 (0) | 2026.04.15 |
|---|---|
| (4949) 균형잡힌 세상 (0) | 2026.04.15 |
| (10773) 제로 (0) | 2026.04.15 |
| (28278) 스택 2 (0) | 2026.04.15 |
| (13909) 창문 닫기 (0) | 2026.04.15 |
