挑战
这是一个简单的挑战。给定两个正整数, w
并h
创建一个宽度为w
,高度为的ASCII栅栏h
。围栏应使用以下规则构造:
- 该
+
角色将代表一个职位。 - 该
-
字符将用于表示围栏的宽度。 - 的
|
将被用于表示围栏的高度。 - 在精确
-
输出了三个字符之后,必须随后输出一个+
字符。除四个角以外,您输出a的任何其他时间都是无效的。您可以从左或从右开始遵循此规则(请参见示例),但是必须保持一致。+
- 在准确
|
输出两个字符之后,必须随后输出一个+
字符。除四个角以外,您输出a的任何其他时间都是无效的。允许您从顶部或底部开始遵循此规则(请参见示例),但是必须保持一致。+
- 每个围栏都将恰好具有四个角,并且每个角将用表示
+
。
换句话说:每三个-
字符必须输出一个+
。并且每两个|
字符必须输出一个+
。
你可以假设栅栏将永远是一个矩形,并且这两个w
和h
永远不会大于100
或小于1
。尾随和/或前导空格是允许的。
示例/测试用例
w = 1
h = 1
+-+
| |
+-+
w = 3
h = 2
+---+
| |
| |
+---+
w = 5
h = 7
+---+--+ or +--+---+
| | | |
| | + +
+ + | |
| | | |
| | + +
+ + | |
| | | |
| | + +
+ + | |
| | | |
+---+--+ +--+---+
w = 10
h = 5
+---+---+---+-+ or +-+---+---+---+
| | | |
| | + +
+ + | |
| | | |
| | + +
+ + | |
| | | |
+---+---+---+-+ +-+---+---+---+
w = 4
h = 4
+---+-+ or +-+---+
| | | |
| | | |
+ + + +
| | | |
| | | |
+---+-+ +-+---+
规则
相关
—
vroomfondel
我是否应该理解可能没有两人
—
xnor
+
的接触?
@xnor是的,这是正确的。
—
Christian Dean
顺便说一句,巨大的第一个挑战。
—
xnor
@LeakyNun你的权利。制定规则时我没有想到这种情况。我添加了一条规则来说明为什么
—
Christian Dean
+-+-+-+-+-+
无效。对困惑感到抱歉。