Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t , n;
- string s;
- cin >> t;
- getline(cin , s);
- while(t--){
- getline(cin , s);
- if(s.empty()){
- cout << "Yes" << endl;
- continue;
- }
- int n = s.size();
- stack<char> my;
- bool f = true;
- for(int i = 0; i < n; i++){
- if((s[i] == '(') || (s[i] == '[')){
- my.push(s[i]);
- continue;
- }
- if(my.empty()){
- f = false;
- break;
- }
- if((my.top() == '[') && (s[i] == ')')){
- f = false;
- break;
- }
- if((my.top() == '(') && (s[i] == ']')){
- f = false;
- break;
- }
- my.pop();
- }
- if(!my.empty()){
- f = false;
- }
- if(f){
- cout << "Yes" << endl;
- }else{
- cout << "No" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement