fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n,dl=0;
  6. string a;
  7. cin>>n;
  8. for(int i=0;i<n;i++)
  9. {
  10. int e=0,h=0;
  11. cin>>a;
  12. dl=a.size();
  13. for(int j=0;j<dl;j++)
  14. {
  15. if(a[j]=='(')
  16. e++;
  17. if(a[j]==')')
  18. h++;
  19. if(h>e||h!=e&&j+1==dl)
  20. {
  21. j=j+260;
  22. e=0;
  23. h=0;
  24. cout<<"FALSE"<<"\n";
  25. }
  26. if(h==e&&j+1==dl)
  27. cout<<"TRUE"<<"\n";
  28.  
  29. }
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 4468KB
stdin
5
()))
(()
(
(())
(((()
stdout
FALSE
FALSE
FALSE
TRUE
FALSE