#include<bits/stdc++.h> using namespace std; int main(){ int n; stack<char>w; cin>>n; getchar(); for(int i = 0;i<n;i++){//控制组数 string s; int flag = 0; getline(cin,s); for(int i = 0;i<s.size();i++){ if(s[i]=='(')w.push(s[i]); else{ if(!w.empty()){ //栈有左括号 w.pop(); }else{ //栈空 flag = 1; break; } } } if(flag)cout<<"No"<<endl; else cout<<"Yes"<<endl; } return 0; } |
Double click to view unformatted code.