fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. void bracket() {
  8. string s;
  9. cin >> s;
  10.  
  11. if (s == "()") {
  12. cout << "NO\n";
  13. return;
  14. }
  15.  
  16. int n = s.length();
  17. string p1 = "";
  18. string p2 = "";
  19.  
  20. for (int i = 0; i < n; ++i) {
  21. p1 += "()";
  22. }
  23.  
  24. for (int i = 0; i < n; ++i) {
  25. p2 += "(";
  26. }
  27. for (int i = 0; i < n; ++i) {
  28. p2 += ")";
  29. }
  30.  
  31. cout << "YES\n";
  32. if (p1.find(s) == string::npos) {
  33. cout << p1 << "\n";
  34. } else {
  35. cout << p2 << "\n";
  36. }
  37. }
  38.  
  39. int main() {
  40. ios_base::sync_with_stdio(false);
  41. cin.tie(NULL);
  42.  
  43. int t;
  44. cin >> t;
  45. while (t--) {
  46. bracket();
  47. }
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 5320KB
stdin
4
)(
(()
()
))()
stdout
YES
(())
YES
()()()
NO
YES
()()()()