時間限制:3000 ms
| 記憶體限制:65535 kb
難度:3
<dl>
<dt>描述</dt>
<dd>現在,有一行括号序列,請你檢查這行括号是否配對。</dd>
</dl>
<dt>輸入</dt>
<dd>第一行輸入一個數n(0<n<=100),表示有n組測試資料。後面的n行輸入多組輸入資料,每組輸入資料都是一個字元串s(s的長度小于10000,且s不是空串),測試資料組數少于5組。資料保證s中隻含有"[","]","(",")"四種字元</dd>
<dt>輸出</dt>
<dd>每組輸入資料的輸出占一行,如果該字元串中所含的括号是配對的,則輸出yes,如果不配對則輸出no</dd>
<dt>樣例輸入</dt>
<dd>
</dd>
<dt>樣例輸出</dt>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
using
namespace std;
int main(int argc, char* argv[])
{
int
n;
cin>>n;
while(n--)
char
c[10005];
cin>>c;
int i,flag=1;
stack<char>
s;
for(i=0;c[i];i++)
if(c[i]==‘(‘||c[i]==‘[‘)
s.push(c[i]);
else
if(s.empty())
{ flag=0; break;}
if((c[i]==‘)‘&&s.top()==‘(‘)||(c[i]==‘]‘&&s.top()==‘[‘))
{ s.pop(); }
flag=0;
break;}
}
if(s.empty()&&flag) cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;