Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:47
Show Gist options
  • Save pinglunliao/6e2e6e432a4615d77ee0 to your computer and use it in GitHub Desktop.
Save pinglunliao/6e2e6e432a4615d77ee0 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
using namespace std;
void prtPattern(int index, int right, int left, char *pattern) {
if(index == right && left == index)
{
puts(pattern - 2 * index);
}
if( right < index )
{
*pattern = '(';
prtPattern(index, right + 1, left, pattern + 1);
}
if( left < right)
{
*pattern = ')';
prtPattern(index, right, left + 1, pattern + 1);
}
}
int main() {
int n;
while(scanf("%d", &n) != EOF)
{
char str[32] = {'\0'};
prtPattern(n, 0, 0, str);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment