push(x) 入栈
pop()出栈
top() 访问栈顶
empty()判断栈空 为空返回true
size() 栈中的元素个数
#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
char change( char c )
{
return c == ']' ? '[' : '(';
}
bool match( char * p )
{
stack <char > q;
while(*p)
{
switch ( *p )
{
case '[':
case '(':
q.push( *p );break;
case ']':
case ')':
if( q.empty() || q.top() != change( *p ) ) return false;
q.pop();
break;
}
p++;
}
if( q.empty() ) return true;
return false;
}
int main()
{
int t;
char str[10010];
scanf("%d",&t);
while (t--)
{
scanf("%s",str);
if( match(str) ) printf("Yes\n");
else printf("No\n");
}
}