这是四向交叉的ASCII艺术:
| | |
| |
| | |
| |
| | |
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
| | |
| |
| | |
| |
| | |
(请注意,水平道路的高度为3行,而垂直道路的宽度为5列。这是出于审美原因,因为是矩形字体。)
您的挑战是产生这种ASCII艺术。但是,正如我确定的大家所知道的,并不是每个交叉路口都有在每个方向上行驶的道路。这个特定的路口走了NESW
,但是某些路口可能走了,例如NW
:
| | |
| |
| | |
| |
| | |
-----+-----+
| |
- - -| |
| |
-----+-----+
否则可能会SWE
:
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
| | |
| |
| | |
| |
| | |
甚至可能E
只是一个方向而已(尽管您几乎不能称其为十字路口,但要尽量避免过于腐):
+-----+-----
| |
| |- - -
| |
+-----+-----
您需要编写一个可以轻松生成这些组合中任何一个的程序或函数。更具体地说,您面临的挑战是编写一个程序或函数,该程序或函数采用由组成的字符串NESW
作为输入,并输出或返回这种ASCII码与交叉路口相交的ASCII艺术。这些方向可以按任意顺序出现,但输入将不包含除了任何字符N
,E
,S
,或W
。如果愿意,可以要求输入小写字母,但是必须在答案中指定。您还可以假设所有输入将至少包含一个方向。
最后一个示例在每条线上都有前导空格,因为没有道路向西行驶。如果您没有向西行驶的道路,那么这些前导空格是可选的。这个:
+-----+-----
| |
| |- - -
| |
+-----+-----
也将是可接受的输出。同样,如果N
或S
不存在,则此处的空行是可选的。允许尾随换行符,并且只要输出在视觉上相同,就允许尾随空格。
您可以采用任何合理的格式进行输入和输出,例如STDIN / STDOUT,命令行参数,文件,函数自变量/返回值等。
像往常一样,这是code-golf,因此请尝试以碰巧使用的任何语言获得最短的答案!
样本IO:
NESW:
| | |
| |
| | |
| |
| | |
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
| | |
| |
| | |
| |
| | |
NS:
| | |
| |
| | |
| |
| | |
+-----+
| |
| |
| |
+-----+
| | |
| |
| | |
| |
| | |
S:
+-----+
| |
| |
| |
+-----+
| | |
| |
| | |
| |
| | |
EW:
-----+-----+-----
| |
- - -| |- - -
| |
-----+-----+-----
SE:
+-----+-----
| |
| |- - -
| |
+-----+-----
| | |
| |
| | |
| |
| | |
E
例如,如果没有)?是开头和结尾的空白行获准如果没有N
或S
?