编写一个程序或函数来绘制一棵树,从而构建一个森林。
树木被画得像堆积金字塔。第一行(顶部)包含1
树,下一行包含2
(总计3
),下一行包含3
(总计6
),依此类推。如果没有足够的树木来完成整行,请将其填充到左侧,将右侧的点留空。此外,较低级别的树由于其位置而略微重叠于较高级别的树。
这是一片森林 1
/\
//\\
///\\\
||
||
这是一片森林 2
/\
//\\
/\///\\\
//\\ ||
///\\\||
||
||
这是一片森林 3
/\
//\\
/\///\\\/\
//\\ || //\\
///\\\||///\\\
|| ||
|| ||
这是一片森林 4
/\
//\\
/\///\\\/\
//\\ || //\\
/\///\\\||///\\\
//\\ || ||
///\\\|| ||
||
||
这是一片大小的森林5
(请注意,第五棵树的顶部覆盖了第一棵树的树干)
/\
//\\
/\///\\\/\
//\\ || //\\
/\///\\\/\///\\\
//\\ || //\\ ||
///\\\||///\\\||
|| ||
|| ||
(跳过一些)
这是一个大小森林8
(扩展模式)
/\
//\\
/\///\\\/\
//\\ || //\\
/\///\\\/\///\\\/\
//\\ || //\\ || //\\
/\///\\\/\///\\\||///\\\
//\\ || //\\ || ||
///\\\||///\\\|| ||
|| ||
|| ||
等等。
输入值
任何方便格式的一个正整数,n > 0
。
输出量
遵循上述规则,以森林的ASCII艺术形式表示。前导/尾随的换行符或其他空格是可选的,前提是所有树都适当排列。
规则
@LuisMendo据我了解,它们按阅读顺序排列。因此,每一行依次被填充,如果整行没有足够的树木,则其余的树应尽可能地放在该行的最左侧。
—
xnor
@LuisMendo xnor正确。如果我可以重新输入文字以使其更清楚,请在聊天中对我执行ping操作。
—
AdmBorkBork
@xnor谢谢,我现在很清楚
—
Luis
@Adm实际上是在挑战中写的。显然我看不懂:-)
—
Luis Mendo
n
的树的位置是什么?