赏心悦目的code:
#include <cstdio>
#define MAXN 19
int num[MAXN]={1,1}, n;
void GetMum(int n){ for(int i=0; i<n; (num[n]+=num[i]*num[n-1-i]), i++); }
void SplitNum(int order, int node)
{
for (int r, l=0;
l<node && (r=node-1-l, order-=num[l]*num[r], order>0) ||
(order+=num[l]*num[r]-1,
l!=0 && (printf("("), SplitNum(order/num[r]+1, l), printf(")")),
printf("X"),
r!=0 && (printf("("), SplitNum(order%num[r]+1, r), printf(")")),
false);
l++);
}
int main()
{
for (int i=2; i<MAXN; i++) GetMum(i);
while(scanf("%d", &n), n)
for(int i=1;i<MAXN && (num[i]<n)||(SplitNum(n, i), printf("\n"), false);n-=num[i++]);
return 0;
}