문제
정답 코드
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i=0;i <n;i++)
{
int p = 0;
string s;
stack <char> st;
cin >> s;
for (auto it : s)
{
if (it == ')')
{
if (st.empty())
{
cout <<"NO\n";
p = 1;
break;
}
st.pop();
}
else if (it == '(')
st.push(it);
}
if (p ==1)
continue;
else if (!st.empty())
cout << "NO\n";
else
cout << "YES\n";
}
}
문제 풀이의 흐름
- 이전에 풀었던 문제인 알고리즘 백준 3986번 좋은단어와 거의 같은 문제이다.
- https://haward.tistory.com/35 링크를 첨부한다.
Uploaded by N2T