#include <iostream>
#include <cstdio>
#include <string>
#include <stack>
#include <cstring>
using namespace std;
int main(){
int n;
string input;
cin >> n;
getchar();
while(n--){
stack <char> container;
getline(cin, input);
if(!input.size()){
cout << "Yes" << endl;continue;
}
if(input.size()%2){
cout << "No" << endl;continue;
}
int flag = 0, sz = input.size();
for(int i = 0; i < sz; i++){
if(input[i] == '(' || input[i] == '[')container.push(input[i]);
else if(!container.empty() && (input[i] == ']' && container.top() == '['))container.pop();
else if(!container.empty() && (input[i] == ')' && container.top() == '('))container.pop();
else{
flag = 1;break;
}
}
if(!flag && container.empty())cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
#include <cstdio>
#include <string>
#include <stack>
#include <cstring>
using namespace std;
int main(){
int n;
string input;
cin >> n;
getchar();
while(n--){
stack <char> container;
getline(cin, input);
if(!input.size()){
cout << "Yes" << endl;continue;
}
if(input.size()%2){
cout << "No" << endl;continue;
}
int flag = 0, sz = input.size();
for(int i = 0; i < sz; i++){
if(input[i] == '(' || input[i] == '[')container.push(input[i]);
else if(!container.empty() && (input[i] == ']' && container.top() == '['))container.pop();
else if(!container.empty() && (input[i] == ')' && container.top() == '('))container.pop();
else{
flag = 1;break;
}
}
if(!flag && container.empty())cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
No comments:
Post a Comment