当我编写文档,注释等时,我喜欢制作ASCII表。它们通常最终看起来还不错,但是我始终觉得它们看起来会更好-特别是因为UTF-8 / Unicode包括了箱形图字符。但是,这些字符的使用非常繁琐,需要多次按键才能插入。你的任务?编写一个程序或函数,可以将ASCII表自动转换为等效的UTF-8 / Unicode。
这个挑战被沙盒化了。
挑战
编写一个程序,该程序将ASCII表作为输入字符串,然后输出用Unicode / UTF-8框绘图字符重绘的表。具体地说,表中的字符应按以下方式翻译:
(Unicode, 3 bytes each in UTF-8)
- to ─ (\u2500)
| to │ (\u2502)
= to ═ (\u2550)
and + to one of:
┌ (\u250C), ┐ (\u2510), └ (\u2514), ┘ (\u2518),
├ (\u251C), ┤ (\u2524), ┬ (\u252C), ┴ (\u2534),
┼ (\u253C)
or, if '=' on either side:
╒ (\u2552), ╕ (\u2555), ╘ (\u2558), ╛ (\u255D),
╞ (\u255E), ╡ (\u2561), ╤ (\u2564), ╧ (\u2567),
╪ (\u256A)
细节
输入/输出:
- 允许默认I / O
- 您可以采用任何合理的格式输入,包括将表作为字符串或包含表的文件的路径。
- 您可以输出到文件,并以文件名作为附加参数。
- 但是,您不能修改输入文件。(应该保留它,以方便将来编辑)
输入:
- 您可以假设输入的每一行都用填充为相同的长度
。
- 您可能不会假定换行符后的第一个字符是表边框的一部分(因为它可能是空格)。
- 如果所有字符(属于表的一部分)
-=|
都完全连接到两个字符,并且+
水平和垂直都连接到至少一个字符,则输入被认为是有效表。 - 您的程序使用有效的输入可能不会产生任何错误。
- 如果输入无效,则行为未定义,您可以产生任何输出。
- 输入内容可以包含任何UTF-8字符,包括方框图字符。
输出:
-=|+
不属于表的任何字符都必须保持原样。- 同样,任何其他字符都必须保持原样。
- 允许使用单个前导和/或尾随的换行符。
其他:
- 像往常一样,禁止出现标准漏洞。
- 如果您的首选语言具有可解决此问题的内置语言,则您可能无法使用它。
- 这意味着程序,函数,子例程或指令将是对此挑战的有效提交,而无需添加任何内容。
- 使用UTF-8编码时,此挑战所需的每个字符长3个字节。
关联字符:
在以下情况下,一个角色已连接到另一个角色:
- 它
|
在+
或的正上方或正下方|
; - 它
-
是直接之前或之后+
或-
; - 它
=
是直接之前或之后+
或=
; - 它是
+
与是直接的上方或下方|
或+
,或者是直接或经过之前-
,=
或+
。
如果字符连接到表中的任何字符,则该字符被视为表的一部分。根据定义,+
输入中的第一个是表的一部分。
例子
此处提供的示例为可复制复制的版本。
Input: Output:
+------------------+ ┌──────────────────┐
| Hello+World! | │ Hello+World! │
+==================+ ╞══════════════════╡
| This is+my first | -> │ This is+my first │
|+-+ code|golf +-+| │+-+ code|golf +-+│
|+-+chall|enge! +-+| │+-+chall|enge! +-+│
+------------------+ └──────────────────┘
+===+===+===+ ╒═══╤═══╤═══╕
| 1 | 2 | 3 | │ 1 │ 2 │ 3 │
+---+===+===+===+ ┌───╪═══╪═══╪═══╡
| 1 | 1 | 2 | 3 | │ 1 │ 1 │ 2 │ 3 │
+---+---+---+---+ -> ├───┼───┼───┼───┤
| 2 | 2 | 4 | 6 | │ 2 │ 2 │ 4 │ 6 │
+---+---+---+---+ ├───┼───┼───┼───┤
|-3 |-3 |-6 |-9 | │-3 │-3 │-6 │-9 │
+===+---+---+---+ ╘═══╧───┴───┴───┘
+-----+ -> <Undefined>
+-----+ -> ┌─────┐
+-----+ └─────┘
+-----------------+
| Hello, World! |
| This is invalid | -> <Undefined>
| input |
-----------------+
++++ ┌┬┬┐
++++ -> ├┼┼┤
++++ └┴┴┘
+--+
++++ -> <Undefined>
+--+
最后...
这是代码高尔夫球,因此最少的字节数获胜。打高尔夫球快乐!
Hello World
表,则内部表不被视为组成一个表,因为该表内部的文本必须保持不变,并且由于它们未正确连接至外部表边界,因此内部表也不被视为外部表边界的一部分。
+-+
摘录视为一个连接表?