Created
July 15, 2016 21:27
-
-
Save astinaam/fd09538e0d5f6b0d9f566c8de892fe57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
// freopen("in.txt","r",stdin); | |
// freopen("out.txt","w",stdout); | |
int n; | |
scanf("%d",&n); | |
getchar(); | |
while(n--) | |
{ | |
string str; | |
getline(cin,str); | |
stack<char> p; | |
bool ok = true; | |
for(int i=0;i<str.size();++i) | |
{ | |
if(str[i]=='(') | |
{ | |
p.push(str[i]); | |
} | |
else if(str[i]=='[') | |
{ | |
p.push(str[i]); | |
} | |
else if(str[i]==')') | |
{ | |
if(!p.empty() && p.top()=='(') | |
{ | |
p.pop(); | |
} | |
else | |
{ | |
ok = false; | |
break; | |
} | |
} | |
else if(str[i]==']') | |
{ | |
if(!p.empty() && p.top()=='[') | |
{ | |
p.pop(); | |
} | |
else | |
{ | |
ok = false; | |
break; | |
} | |
} | |
} | |
if(!p.empty()) | |
ok = false; | |
if(ok) puts("Yes"); | |
else puts("No"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UVa 673 #stack