Using two characters: . (dot) and * (asterisk) print a grid-like pattern. The grid will have l lines, c columns, and each square shaped element of the grid will have the height and width equal to s.
Moreover, each of the grid elements will have a diagonal. The diagonal of the first square in the first line of the grid is directed towards down and right corner - use the \ (backslash) character to print it; while the next diagonal will be directed towards upper right corner - use the / (slash) character to print it. Print the successive diagonals alternately (please consult the example below).
Input
You are given t - the number of test cases and for each of the test case three positive integers: l - the number of lines, c - the number of columns in the grid and s - the size of the single square shaped element.
Output
For each of the test cases output the requested pattern (please have a look at the example). Use one line break in between successive patterns.
Example
Input: 3 3 1 2 4 4 1 2 5 2 Output: **** *\.* *.\* **** *./* */.* **** *\.* *.\* **** ********* *\*/*\*/* ********* */*\*/*\* ********* *\*/*\*/* ********* */*\*/*\* ********* **************** *\.*./*\.*./*\.* *.\*/.*.\*/.*.\* **************** *./*\.*./*\.*./* */.*.\*/.*.\*/.* ****************题意:给出行,列及方块的大小 ,输出如下的字符,每个方格的对角线为左上->右下,后序的相反
思路:1、row % (s+1) = 0 或者col%(s+1)=0输出*
2、(row+col)%(2*s+2) = 0输出\
3、(row-col)%(2*s+2)=0输出/
代码如下:
t = int(input())
for cas in range(t):
line = input();
a = line.split(' ');
l = int(a[0])
c = int(a[1])
s = int(a[2])
row = l * (s + 1) + 1
col = c * (s + 1) + 1
for i in range(row):
for j in range(col):
if (0 == i % (s + 1) or 0 == j % (s + 1)):
print('*', sep = '', end = '')
elif (0 == (i + j) % (2 * s + 2)):
print('/', sep = '', end = '')
elif (0 == (i - j) % (2 * s + 2)):
print('\\', sep = '', end = '')
else:
print('.', sep = '', end = '')
print()