输入字符串个数N,然后输入N个字符串(只含有[] ()四种字符),对每个字符串进行匹配,匹配成功输出Yes ,失败输出No
/*
#include "iostream"
#include "string"
using namespace std;
#define maxsize 100
#define str_maxsize 10000
int matching(string parenthesis)
{
char temp[str_maxsize] = "";
int top = -1;
for (int i = 0; i < parenthesis.length(); i++)
{
if (i == 0)
{
top++;
temp[top] = parenthesis[i];
}
else if (i > 0)
{
if (parenthesis[i] == ']' && temp[top] == '[')
{
top--;
}
else if (parenthesis[i] == ')' && temp[top] == '(')
{
top--;
}
else
{
top++;
temp[top] = parenthesis[i];
}
}
}
if (top == -1)
return 1;
else
return 0;
}
int main()
{
string parenthesis[maxsize];
int N = 0;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> parenthesis[i];
}
for (int i = 0; i < N; i++)
{
if (parenthesis[i] == "")
break;
else
{
if (matching(parenthesis[i]) == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
system("pause");
return 0;
}
*/
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
vector<char> vec;
string ch;
vec.push_back(' ');
cin >> ch;
for (int i = 0; i<ch.length(); i++)
{
vec.push_back(ch[i]);
if (vec.back() - 1 == *(vec.end() - 2) || vec.back() - 2 == *(vec.end() - 2))
{
vec.pop_back();
vec.pop_back();
}
}
if (vec.size() == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
system("pause");
return 0;
}