fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main() {
  5. const int N = 6;
  6. std::string str;
  7. int opens = 0, closes = 0;
  8. do {
  9. for (;opens < N; ++opens) {
  10. str += '(';
  11. }
  12. for (;closes < N; ++closes) {
  13. str += ')';
  14. }
  15. std::cout << str << std::endl;
  16.  
  17. // find the open to swap
  18. while(str.size() > 0) {
  19. char c = str.back();
  20. str.pop_back();
  21. if (c==')') {
  22. --closes;
  23. } else {
  24. --opens;
  25. if (opens > closes) {
  26. str += ')';
  27. ++closes;
  28. break;
  29. }
  30. }
  31. }
  32. } while (!str.empty());
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5460KB
stdin
Standard input is empty
stdout
(((((())))))
((((()()))))
((((())())))
((((()))()))
((((())))())
((((()))))()
(((()(()))))
(((()()())))
(((()())()))
(((()()))())
(((()())))()
(((())(())))
(((())()()))
(((())())())
(((())()))()
(((()))(()))
(((()))()())
(((()))())()
(((())))(())
(((())))()()
((()((()))))
((()(()())))
((()(())()))
((()(()))())
((()(())))()
((()()(())))
((()()()()))
((()()())())
((()()()))()
((()())(()))
((()())()())
((()())())()
((()()))(())
((()()))()()
((())((())))
((())(()()))
((())(())())
((())(()))()
((())()(()))
((())()()())
((())()())()
((())())(())
((())())()()
((()))((()))
((()))(()())
((()))(())()
((()))()(())
((()))()()()
(()(((()))))
(()((()())))
(()((())()))
(()((()))())
(()((())))()
(()(()(())))
(()(()()()))
(()(()())())
(()(()()))()
(()(())(()))
(()(())()())
(()(())())()
(()(()))(())
(()(()))()()
(()()((())))
(()()(()()))
(()()(())())
(()()(()))()
(()()()(()))
(()()()()())
(()()()())()
(()()())(())
(()()())()()
(()())((()))
(()())(()())
(()())(())()
(()())()(())
(()())()()()
(())(((())))
(())((()()))
(())((())())
(())((()))()
(())(()(()))
(())(()()())
(())(()())()
(())(())(())
(())(())()()
(())()((()))
(())()(()())
(())()(())()
(())()()(())
(())()()()()
()((((()))))
()(((()())))
()(((())()))
()(((()))())
()(((())))()
()((()(())))
()((()()()))
()((()())())
()((()()))()
()((())(()))
()((())()())
()((())())()
()((()))(())
()((()))()()
()(()((())))
()(()(()()))
()(()(())())
()(()(()))()
()(()()(()))
()(()()()())
()(()()())()
()(()())(())
()(()())()()
()(())((()))
()(())(()())
()(())(())()
()(())()(())
()(())()()()
()()(((())))
()()((()()))
()()((())())
()()((()))()
()()(()(()))
()()(()()())
()()(()())()
()()(())(())
()()(())()()
()()()((()))
()()()(()())
()()()(())()
()()()()(())
()()()()()()