括号匹配。坑的就是空字符串,,空串!空串!空串
附上参考资料。c/c++输入带空格的字符串用法总结
http://blog.csdn.net/zhouwei1221q/article/details/44887899
原题链接
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=614
ac代码
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main()
{
int t;
cin>>t;
getchar();
while(t--)
{
stack<char> s;
string kuohao;
getline(cin,kuohao);
int chang = kuohao.length();
for(int i=0;i<chang;i++)
{
if(chang == 0)
{
printf("Yes\n");
continue;
}
else if(kuohao[i]=='('||kuohao[i]=='[')
s.push(kuohao[i]);
else if(kuohao[i]==')')
{
if(s.size()&&s.top()=='(')
s.pop();
else
s.push(kuohao[i]);
}
else if(kuohao[i]==']')
{
if(s.size()&&s.top()=='[')
s.pop();
else
s.push(kuohao[i]);
}
}
if(s.size())
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
return 0;
}