35657

Untitled

Oct 12th, 2024
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void bracket(int count, std::string s = "", int left = 0, int right = 0) {
  4.     if (left == count && right == count) {
  5.         std::cout << s << std::endl;
  6.         return;
  7.     }
  8.     if (left < count) {
  9.         bracket(count, s + '(', left + 1, right);
  10.     }
  11.     if (right < left) {
  12.         bracket(count, s + ')', left, right + 1);
  13.     }
  14. }
  15.  
  16. int main() {
  17.     int count;
  18.     std::cin >> count;
  19.     bracket(count);
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment