#include<stdio.h> #include<math.h> #include<string.h> //#include<algorithm> #include <bits/stdc++.h> using namespace std; int main() { int T; scanf("%d",&T); getchar(); while(T--) { string str; // scanf("%s",str); // gets(str); getline(cin,str); int panduan=0; int left=0; for(int i=0; i<str.length(); i++) { if(str[i]=='(') { left++; } else { left--; } if(left<0) { panduan=1; break; } } if(panduan==0&&left==0) { printf("Yes\n"); } else { printf("No\n"); } } } |
Double click to view unformatted code.