- Code: Select all
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n, stk, stack[128], check, wrong;
string str;
cin >> n;
cin.ignore (80, '\n');
for (int i = 0; i < n; i++)
{
getline(cin, str);
if (str == "")
stk = 0;
else
{
stk = 0;
wrong = 0;
for (int j = 0; j < str.size(); j++)
{
if (str[j] == '(')
{
stack[stk] = 41;
stk++;
}
else if (str[j] == '[')
{
stack[stk] = 93;
stk++;
}
else if (str[j] == ')')
{
if (stack[stk - 1] == 41)
stk = stk - 1;
else
{
wrong = 1;
break;
}
}
else if (str[j] == ']')
{
if (stack[stk - 1] == 93)
stk = stk - 1;
else
{
wrong = 1;
break;
}
}
}
}
if (stk == 0 && wrong == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
Why kept getting WA...?????
