Ankit_132

A

Aug 17th, 2023
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     _test
  13.     {
  14.         string s;
  15.         cin>>s;
  16.  
  17.         int n = s.size();
  18.  
  19.         string a = "";
  20.         string b = "";
  21.  
  22.         a.pb('(');
  23.  
  24.         while(a.size() < 2*n)
  25.         {
  26.             if(a.back() == '(')     a.pb(')');
  27.             else                    a.pb('(');
  28.         }
  29.  
  30.         while(b.size() < n)     b.pb('(');
  31.         while(b.size() < 2*n)   b.pb(')');
  32.  
  33.         if(a.find(s) == string::npos)
  34.             cout<<"YES\n"<<a<<"\n";
  35.         else if(b.find(s) == string::npos)
  36.             cout<<"YES\n"<<b<<"\n";
  37.         else
  38.             cout<<"NO\n";
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment