#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
vector<char> v;
string str;
int idx = -1;
while (1)
{
getline(cin, str);
v.clear();
if (str == ".")
return 0;
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == '(' || str[i] == '[' || str[i] == ')' || str[i] == ']')
{
char temp = str[i];
v.push_back(temp);
// cout << idx << ' ' << v.at(idx) << endl;
idx++;
if (temp == ')')
{
if (v[idx - 1] == '(')
{
v.pop_back();
v.pop_back();
idx -= 2;
}
}
else if (temp == ']')
{
if (v[idx - 1] == '[')
{
v.pop_back();
v.pop_back();
idx -= 2;
}
}
}
}
if (v.size() < 1 || str == " .")
{
cout << "yes" << '\n';
}
else
{
cout << "no" << '\n';
}
}
return 0;
}
#include <iostream>
#include <stack>
using namespace std;
int main(int argc, char const *argv[])
{
while (1)
{
stack<char> st;
string str;
getline(cin, str);
if (str == ".")
return 0;
int flag = 0;
for (int i = 0; i < str.size(); i++)
{
char temp = str[i];
if (temp == '(' || temp == '[')
{
st.push(temp);
}
else if (temp == ')')
{
if (st.empty() || st.top() != '(')
{
flag = 1;
break;
}
st.pop();
}
else if (temp == ']')
{
if (st.empty() || st.top() != '[')
{
flag = 1;
break;
}
st.pop();
}
}
if (flag || !st.empty())
{
cout << "no" << '\n';
}
else
{
cout << "yes" << '\n';
}
}
return 0;
}
flag
를 잘 써봐야겟다..