ASCII艺术很有趣。现代文本编辑器非常擅长处理文本。现代编程语言可以胜任吗?
ASCII艺术处理中的一项常见任务是将文本裁剪为两个字符之间的矩形。这是您在此挑战中必须执行的任务。
细节
您的程序将接受3个输入:
- 第一个是块的“开始”字符-标记左上角
- 第二个是块的“结束”字符-标记右下角
- 第三种是某种形式的多行文本,可以是字符串,也可以是字符串列表,或者是文件名,或者其他任何形式
结果将是多行文本(同样以上述任何一种格式)被裁剪为给定输入之间的矩形。请注意,前两个输入可能不是唯一的。
边缘情况
盒子的体积必须始终至少为2。因此,这些:
() (
)
是盒子,但这些:
)( ) (
( )
不是(带有start = (
和end = )
)。
输入将仅包含一个框。因此,开始和结束字符只能出现一次,除非它们是相同的字符,在这种情况下,它们必须恰好出现两次。
此外,输入中的每一行必须至少与从行首到输入中框的右边缘的距离一样长。
您的程序不需要处理无效的输入。它们可能导致不确定的行为。
规则
适用典型的代码高尔夫球规则。最短的代码获胜。
例子
晴天: start: ( end: ) input:
This is some text
. (but this text
is in a box ).
So only it is important.
输出:
(but this text
is in a box )
注意水平空间的剥离。ASCII艺术品是二维的。
下雨天: start: ( end: ) input:
This is some text (
But is that even )
really a box?
输出:
(
)
相同的开始/结束: start: / end: / input:
Oh, I get how this could be useful
/----------------------------\
| All this text is in a box! |
\----------------------------/
输出:
/----------------------------\
| All this text is in a box! |
\----------------------------/
输入无效: start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.
无效的输入2: start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)