编写一个程序或函数,该程序或函数采用正整数N,并打印或返回N×N ASCII艺术字串,其上半部分是由组成的半圆(
,下半部分是由组成的下指三角形V
,并且用作填充的空格。
换句话说,制作一个ASCII冰淇淋蛋筒:(N = 17的输出)
(((((
(((((((((
(((((((((((((
(((((((((((((
(((((((((((((((
(((((((((((((((
(((((((((((((((((
(((((((((((((((((
VVVVVVVVVVVVVVVVV
VVVVVVVVVVVVVVV
VVVVVVVVVVVVV
VVVVVVVVVVV
VVVVVVVVV
VVVVVVV
VVVVV
VVV
V
例子
这是N = 1至5的输出。请注意,对于奇数N,三角形始终必须是较大的一半。
V
((
VV
(((
VVV
V
((
((((
VVVV
VV
(((
(((((
VVVVV
VVV
V
这是一个非公开的Python 3参考实现:
N = int(input())
ic = [[' '] * N for _ in range(N)]
for y in range(N//2):
for x in range(N):
if (x - (N - 1) / 2)**2 + (y - (N - 1) / 2)**2 < (N / 2)**2:
ic[y][x] = '('
for y in range(N//2, N):
for x in range(y - N//2, N - (y - N//2)):
ic[y][x] = 'V'
for line in ic:
print(''.join(line))
细节
- 从标准输入,命令行或函数参数获取输入。输出到stdout或类似文件,或者如果编写函数,则可以返回字符串。
- 圆锥部分应与所有N的参考实现完全匹配。
- 冰淇淋部分也没有必要精确的参考实现,只要它显然是一个半圆形的所有N.(这是使你不必有关在半圆由于舍入误差的细微差别担心匹配)
- 不应有任何不必要的前导空格,但可能会有多余的尾随空格。
- 输出可以选择包含尾随换行符。
- 您可以选择使用任何其他3级不同的打印的ASCII到位的人物
(
,V
和空间。
计分
以字节为单位的最短提交获胜。决胜局(Tiebreaker)提交时间最久。