这是我朋友的生日,因为他是一名程序员和ASCII艺术爱好者,所以我想我可以给他做一些ASCII蛋糕!
可悲的是,我一直忘了他的年龄,所以我想为我的ASCII烤箱准备一个程序,用指定数量的蜡烛烤蛋糕,所以如果我错了他,我就不必自己再做一次年龄。
ASCII烤箱仅具有有限的内存和存储容量,因此应使用尽可能少的字节。
你的任务:
编写一个程序,将一个生日蛋糕输出到控制台,其中蜡烛的数量与输入指定的数量相同。
蛋糕要求是:
- 它必须具有由水平
-
和垂直|
线以及顶点组成的边界+
。 - 至少5个字符(包括蛋糕边框
|
) - 高至少5个字符(包括蛋糕边框
-
) 蛋糕边框和第一个烛台(不是火焰)之间必须有一个空白字符,除非该空间中有火焰,否则每边都必须有一个空白字符。火焰或蜡烛基不应与蛋糕边界重叠。
- 蛋糕的最大宽度为9个字符,因此每行最多5个蜡烛。
- 由于我们不希望蛋糕是二维的,因此蛋糕必须高2行才能使其具有一定的体积。添加另一个边框底部和连接顶点与上面摆着的,再次使用从上面的ASCII字符(
-
,|
和+
)。
蜡烛的要求是:
- 由底座
|
和火焰组成*
,火焰堆叠在底座上。 - 除对角线外,蜡烛可能不会彼此直接相邻。
- 蜡烛从左到右放置,然后从上到下放置,每行最多5条蜡烛。
(注意:如果上一行有5支蜡烛,则下一行也不能有5支蜡烛,因为它们将相邻。)
补充说明:
- 蛋糕的宽度取决于第一行中蜡烛的数量,但宽度必须至少为5个字符,最大为9个字符。
- 蜡烛从最上一行开始填充,从左到右。如果一行已满,则下一行应从第一行下面的行开始。
输入:
您可以接受自己喜欢的(合理的)格式的数字。
对于这个挑战,即使我不承认这个年龄的人,您也可以假设该数字在0到2 31之间(不包括0)。
输出:
您可以返回一个字符串,也可以将结果蛋糕直接写入输出控制台。
规则:
例子:
输入: 8
+-----------+
| * * * * * |
| |*|*|*| | |
| | | | |
| |
+-----------+
| |
+-----------+
输入: 2
+-----+
| * * |
| | | |
| |
+-----+
| |
+-----+
输入: 12
+-----------+
| * * * * * |
| |*|*|*|*| |
| *|*|*| | |
| | | | |
| |
+-----------+
| |
+-----------+
祝好运!
输入可以有多个有效的解决方案吗?
—
Officialaimm
@officialaimm由于存在蜡烛订购和蛋糕尺寸的规范,因此应该不可能。
—
伊恩·
没用的事实:如果您每隔一秒钟而不是每年庆祝一次生日,那么2 ^ 31〜= 68岁。但这每天都会产生很多蛋糕,一段时间后可能会变得乏味。
—
Arnauld
@Arnauld但由于当时它不是你的生日:( ......除非你正在庆祝的一般事实,你出生的时候99%。
—
伊恩·H.
@IanH。假设您正在庆祝自己的开始时间戳。:-)
—
Arnauld