#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #define N 100 using namespace std; int main() { int t; scanf("%d",&t); while(t--) { getchar(); char str[100000]; int k=0,leap=0; //gets(str); scanf("%s",str); for(int i=0;i<strlen(str);i++) { if(str[i]=='(') k++; else if(str[i]==')'&&k>0) k--; else if(str[i]==')'&&k<=0) { leap=1; break; } } if(k==0&&leap==0) { printf("Yes\n"); } else printf("No\n"); } return 0; } |
Double click to view unformatted code.