挑战
我们都知道普通的圣诞树-但是倒挂的圣诞树呢!这是一个相当容易的圣诞节主题挑战。挑战的目的是使我成为一棵ASCII颠倒的圣诞树。以下是此挑战的规则:
- 接受一个奇数正整数。您可以假设它始终在
7和之间51。 树的底部将由以下字符组成:
___ \ / |树的顶部(星星)将由一个组成
*。树的每一行都将使用
<?>其中?任意数量-s 的格式构造。例如,如果制作一条长度5为的线,则该线应为<--->。或者,如果要画一条长度的线,那条8线应该是<------>。这是树体的构造方法:
以
n给定的奇数为输入,并创建长度为该树的线。减去
4从n并创建一个行树长度。减去
2从n并创建一个行树长度。递减
n的2。此后,除非n等于5,否则返回步骤2。
底数(请参阅步骤2),星形(请参阅步骤3)和树的每一行(请参阅步骤4和5.)均应以原始奇数输入(请参阅步骤1)为中心。宽度。
示例/测试用例
odd number inputed: 7
___
\ /
|
<-----> line length -> 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
odd number inputed: 13
___
\ /
|
<-----------> line length -> 13
<-------> line length -> 13 - 4 = 9
<---------> line length -> 13 - 2 = 11
<-----> line length -> 11 - 4 = 7
<-------> line length -> 11 - 2 = 9
<---> line length -> 9 - 4 = 5
<-----> line length -> 9 - 2 = 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
odd number inputed: 9
___
\ /
|
<-------> line length -> 9
<---> line length -> 9 - 4 = 5
<-----> line length -> 9 - 2 = 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
odd number inputed: 17
___
\ /
|
<---------------> line length -> 17
<-----------> line length -> 17 - 4 = 13
<-------------> line length -> 17 - 2 = 15
<---------> line length -> 15 - 4 = 11
<-----------> line length -> 15 - 2 = 13
<-------> line length -> 13 - 4 = 9
<---------> line length -> 13 - 2 = 11
<-----> line length -> 11 - 4 = 7
<-------> line length -> 11 - 2 = 9
<---> line length -> 9 - 4 = 5
<-----> line length -> 9 - 2 = 7
<-> line length -> 7 - 4 = 3
<---> line length -> 7 - 2 = 5
*
规则
repeat the above steps until the odd number minus 2 equals 5在第一个输入中,奇数是7,并且7-2 = 5,因此树应该立即结束(我知道你的意思,但是它需要改写)
7最小输入为奇数,则首先创建三行树(子步骤.1.1,.1.2,.1.3),然后2从奇数中减去并测试其是否相等5。最后检查“奇数减2等于5”的指令应首先执行其他三个步骤。但是要回答您的第一个评论,那很好。
7输入或是否可以接受4,如第四个奇数(或3它是否为0索引)。