#include <stdio.h> #include <math.h> #include <string.h> int main(){ int t; int count; char str[100000]; scanf("%d",&t); int flag; while(t--){ flag=1; count=0; scanf("%s",str); for(int i=0;i<strlen(str);i++){ if(str[i]=='(') count++; else{ count--; } if(count<0){ flag=0; break; } } if(count!=0) flag=0; if(flag) printf("Yes\n"); else printf("No\n"); } } |
Double click to view unformatted code.