Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void bracket(int count, std::string s = "", int left = 0, int right = 0) {
- if (left == count && right == count) {
- std::cout << s << std::endl;
- return;
- }
- if (left < count) {
- bracket(count, s + '(', left + 1, right);
- }
- if (right < left) {
- bracket(count, s + ')', left, right + 1);
- }
- }
- int main() {
- int count;
- std::cin >> count;
- bracket(count);
- }
Advertisement
Add Comment
Please, Sign In to add comment