Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void addParenthesis(char* str, const int& pos, const int& left, const int& right)
- {
- if (left < 0 || right < left)
- return;
- if (left == 0 && right == 0)
- {
- cout << str << '\n';
- return;
- }
- str[pos] = '(';
- addParenthesis(str, pos + 1, left - 1, right);
- str[pos] = ')';
- addParenthesis(str, pos + 1, left, right - 1);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n = 0;
- cin >> n;
- char* str = new char[2*n+1];
- str[2*n] = '\0';
- addParenthesis(str, 0, n, n);
- delete []str;
- return 0;
- }
- /*
- 2
- (())
- ()()
- 3
- ((()))
- (()())
- (())()
- ()(())
- ()()()
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement