简单栈题
#include<bits/stdc++.h> using namespace std; int main() { int cas;cin>>cas;getchar(); string ss; while(cas--) { stack<char>s;char ch; getline(cin,ss);int ok=1; for(int i=0;i<ss.size();i++) { // printf("%c ",ss[i]); if(ss[i]=='('||ss[i]=='[')s.push(ss[i]); else if(ss[i]==')'&&!s.empty()) { ch=s.top();s.pop(); if(ch!='('){ok=0;break;} } else if(ss[i]==']'&&!s.empty()) { ch=s.top();s.pop(); if(ch!='['){ok=0;break;} } else if(ss[i]==' ')continue; else {ok=0;break;} } if(!s.empty())ok=0; printf("%s ",ok?"Yes":"No"); } }