35657

Untitled

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