编写一个包含三个正整数W,H和N的程序或函数。打印或返回W的H×H网格,.
其中.
正常英语阅读顺序中的每N个N均被替换为X
。
例如,给定W = 7,H = 3,N = 3,网格的宽度为7个字符,高度为3个,从左上角读取的每三个字符为X
:
..X..X.
.X..X..
X..X..X
同样,如果输入为W = 10,H = 4,N = 5,则输出为:
....X....X
....X....X
....X....X
....X....X
笔记
- “普通英语阅读顺序”是指从上一行到下一行从左到右。
- 当N为1时,所有
.
的将成为X
。 - 您可以使用任意两个不同的可打印ASCII字符代替
.
和X
。- 如果使用空格(
- 您可能无法使用其他方式代替形成网格的换行符。
- 如果使用空格(
- W,H和N的确切输入格式和顺序并不重要。诸如此类的东西
[H,W,N]
还是N\nW,H
可以的。 - 输出中尾随换行符就可以了。
- 以字节为单位的最短代码胜出!
例子
W = 5, H = 3, N = 1
XXXXX
XXXXX
XXXXX
W = 5, H = 3, N = 2
.X.X.
X.X.X
.X.X.
W = 5, H = 3, N = 3
..X..
X..X.
.X..X
W = 5, H = 3, N = 4
...X.
..X..
.X...
W = 5, H = 3, N = 5
....X
....X
....X
W = 5, H = 3, N = 6
.....
X....
.X...
W = 5, H = 3, N = 7
.....
.X...
...X.
W = 5, H = 3, N = 15
.....
.....
....X
W = 5, H = 3, N = 16 (or more)
.....
.....
.....
W = 1, H = 1, N = 1
X
W = 1, H = 1, N = 2 (or more)
.
W = 8, H = 6, N = 2
.X.X.X.X
.X.X.X.X
.X.X.X.X
.X.X.X.X
.X.X.X.X
.X.X.X.X
W = 8, H = 6, N = 3
..X..X..
X..X..X.
.X..X..X
..X..X..
X..X..X.
.X..X..X
W = 8, H = 6, N = 4
...X...X
...X...X
...X...X
...X...X
...X...X
...X...X
W = 8, H = 6, N = 7
......X.
.....X..
....X...
...X....
..X.....
.X......
W = 8, H = 6, N = 16
........
.......X
........
.......X
........
.......X
W = 37, H = 1, N = 4
...X...X...X...X...X...X...X...X...X.
W = 1, H = 10, N = 8
.
.
.
.
.
.
.
X
.
.
["..X..X.", ".X..X..", "X..X..X"]
作为网格返回 ”?