fork(18) download
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int i=1, j, x, y, a, b, k, c;
  6. char tab[5009];
  7.  
  8. scanf("%d",&c);
  9. for(j=0;j<c;++j)tab[j]='(';
  10. for(j=c;j<2*c;++j)tab[j]=')';
  11. while(1)
  12. {
  13. printf("%d.\t%s\n",i++,tab);
  14. for(x=1,j=2*c-2;j>=0;j-=2)
  15. if(tab[j]=='('&&tab[j+1]==')')++x;
  16. else break;
  17. if(x-1==c)break;
  18. for(j=2*c-2,y=0;j;--j)
  19. {
  20. if(tab[j]=='(')++y;
  21. if(y==x)break;
  22. }
  23. tab[j]=')';tab[j+1]='(';
  24. for(a=b=0,k=j+2;k<2*c;++k)
  25. if(tab[k]=='(')++a;
  26. else ++b;
  27. for(k=j+2;k<2*c;++k)
  28. if(k-j-2<a)tab[k]='(';
  29. else tab[k]=')';
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0.02s 1724KB
stdin
5
stdout
1.	((((()))))
2.	(((()())))
3.	(((())()))
4.	(((()))())
5.	(((())))()
6.	((()(())))
7.	((()()()))
8.	((()())())
9.	((()()))()
10.	((())(()))
11.	((())()())
12.	((())())()
13.	((()))(())
14.	((()))()()
15.	(()((())))
16.	(()(()()))
17.	(()(())())
18.	(()(()))()
19.	(()()(()))
20.	(()()()())
21.	(()()())()
22.	(()())(())
23.	(()())()()
24.	(())((()))
25.	(())(()())
26.	(())(())()
27.	(())()(())
28.	(())()()()
29.	()(((())))
30.	()((()()))
31.	()((())())
32.	()((()))()
33.	()(()(()))
34.	()(()()())
35.	()(()())()
36.	()(())(())
37.	()(())()()
38.	()()((()))
39.	()()(()())
40.	()()(())()
41.	()()()(())
42.	()()()()()