반응형
https://www.acmicpc.net/problem/4949
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#include<cstring>
#include<sstream>
#include<deque>
#include<cmath>
using namespace std;
//성공
string s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
getline(cin, s);
while (s != ".")
{
stack<char> st;
bool isEmpty = false;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '(' || s[i] == '[')
st.push(s[i]);
else if ((s[i] == ')' || s[i] == ']') && st.empty()
|| (s[i] == ')' && st.top() != '(')
|| (s[i] == ']' && st.top() != '['))
{
isEmpty = true;
break;
}
else if ((s[i] == ')' && st.top() == '(') || (s[i] == ']' && st.top() == '['))
st.pop();
}
if (isEmpty || st.size() != 0)
cout << "no\n";
else
cout << "yes\n";
getline(cin, s);
}
}
반응형