问题描述
请把纸条竖着放在桌⼦上,然后从纸条的下边向上⽅对折,压出折痕后再展 开。此时有1条折痕,突起的⽅向指向纸条的背⾯,这条折痕叫做“下”折痕 ;突起的⽅向指向纸条正⾯的折痕叫做“上”折痕。如果每次都从下边向上⽅ 对折,对折N次。请从上到下计算出所有折痕的⽅向。
给定折的次数n,请返回从上到下的折痕的数组,若为下折痕则对应元素为"down",若为上折痕则为"up".
void Fold(int N)
{
process(1, N, true);
}
void process(int i,int N,bool down)
{
if (i > N)
return;
process(i + 1, N, true);
char *s = down ? "down" : "up";
printf("%s\n", s);
process(i + 1, N, false);
}
其中i代表当前层数,N代表一共折纸次数,down为true时为凹即down,为false时为凸即up