비트맵 코드를 입력받으면 비트맵 그림을 출력해주는 프린터를 작성합니다. 먼저 해상도(세로크기 및 가로크기)를 입력받은 후, 비트맵 코드를 입력받으면 각 라인당 홀수번째 수만큼 흰색 픽셀'□'을 출력, 짝수번째 수만큼 검은색 픽셀'■'을 문자로 출력합니다. (코드의 첫 숫자는 항상 흰색 픽셀의 숫자를 의미하므로, 라인의 첫번째 픽셀이 검은색일 경우 그 라인의 코드는 0으로 시작합니다.)
#Input1
height&width: 6 6
1 3 1
4 1
1 4
0 1 3 1
0 1 3 1
1 4
#Output1
□ ■ ■ ■ □
□ □ □ □ ■
□ ■ ■ ■ ■
■ □ □ □ ■
■ □ □ □ ■
□ ■ ■ ■ ■
#Input2
height&width: 9 18
4 11
4 9 2 1
4 9 2 1
4 11
4 9
4 9
5 7
0 17
1 15
#Output2
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ ■ ■ □ □ ■
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ ■ ■ □ □ ■
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ ■ ■
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ ■ ■
□ □ □ □ □ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
□ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■
#Input3
height&width: 13 18
6 5 2 3
4 2 5 2 3 1
3 1 9 1 2 1
3 1 9 1 1 1
2 1 11 1
2 1 10 2
2 1 9 1 1 1
2 1 8 1 2 1
2 1 7 1 3 1
1 1 1 1 4 2 3 1
0 1 2 1 2 2 5 1
0 1 3 2 5 2
1 3 2 5
#Input 4
height&width: 17 18
6 2 2 2
5 1 2 2 2 1
6 6
4 2 6 2
3 1 10 1
2 1 12 1
2 1 3 1 4 1 3 1
1 2 12 2
0 1 16 1
0 1 6 1 2 1 6 1
0 1 7 2 7 1
1 1 14 1
2 1 12 1
2 1 5 2 5 1
3 1 10 1
4 2 6 2
6 6
#Input5
height&width: 15 15
4 7 4
2 3 5 3 2
1 2 9 2 1
1 1 11 1 1
0 2 11 2
0 1 3 2 3 2 3 1
0 1 3 2 3 2 3 1
0 1 13 1
0 1 2 1 7 1 2 1
0 1 2 2 5 2 2 1
0 2 2 2 3 2 2 2
1 1 3 5 3 1 1
1 2 9 2 1
2 3 5 3 2
4 7 4
20개의 풀이가 있습니다.
Python 3
def main():
bp = BitmapPrinter()
print(bp)
class BitmapPrinter:
def __init__(self):
self._reader()
def _reader(self):
(self.height, self.width) = (int(s) for s in input("Height & Width: ").strip().split())
self.matrix = []
for h in range(self.height):
lineinput = (int(s) for s in input().strip().split())
newstr = [("□" if i % 2 == 0 else "■") * v for i, v in enumerate(lineinput)]
self.matrix.append(" ".join("".join(newstr)))
def __str__(self):
return "\n".join(self.matrix)
if __name__ == '__main__':
main()
package bitmap_printer;
import java.util.Scanner;
public class BitmapPrinter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i, j, k;
boolean color;
/*해상도 입력*/
System.out.println("How many height and width:");
int input_height = in.nextInt();
int input_width = in.nextInt();
String[] input_raw = new String[input_height]; //날 것 그대로 입력
int[][] input = new int[input_height][input_width+1]; //입력 값을 배열에 정리
int[] input_length = new int[input_height]; //입력 값 길이
/*값 입력*/
String dummy = in.nextLine();
for(i=0; i<input_height; i++) {
input_raw[i] = in.nextLine();
}
/*입력 값을 배열에 정리*/
for(i=0; i<input_height; i++) {
for(j=0, k=0; j<input_raw[i].length(); j++){
if(input_raw[i].charAt(j)>=48 && input_raw[i].charAt(j)<=57)
input[i][k]=input[i][k]*10+(input_raw[i].charAt(j)-48);
else if(input_raw[i].charAt(j)==' ') {
k++;
input_length[i]++;
}
}
input_length[i]++;
}
/*출력*/
for(i=0; i<input_height; i++) {
color=false;
for(j=0; j<input_length[i]; j++) {
for(k=0; k<input[i][j]; k++) {
if(color==true) System.out.print("■");
else System.out.print("□");
System.out.print(" ");
}
color=!color;
}
System.out.println();
}
}
}
#Output3
□ □ □ □ □ □ ■ ■ ■ ■ ■ □ □ ■ ■ ■
□ □ □ □ ■ ■ □ □ □ □ □ ■ ■ □ □ □ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ ■ □ □ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ ■ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ ■ ■
□ □ ■ □ □ □ □ □ □ □ □ □ ■ □ ■
□ □ ■ □ □ □ □ □ □ □ □ ■ □ □ ■
□ □ ■ □ □ □ □ □ □ □ ■ □ □ □ ■
□ ■ □ ■ □ □ □ □ ■ ■ □ □ □ ■
■ □ □ ■ □ □ ■ ■ □ □ □ □ □ ■
■ □ □ □ ■ ■ □ □ □ □ □ ■ ■
□ ■ ■ ■ □ □ ■ ■ ■ ■ ■
#Output4
□ □ □ □ □ □ ■ ■ □ □ ■ ■
□ □ □ □ □ ■ □ □ ■ ■ □ □ ■
□ □ □ □ □ □ ■ ■ ■ ■ ■ ■
□ □ □ □ ■ ■ □ □ □ □ □ □ ■ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ ■ □ □ □ □ ■ □ □ □ ■
□ ■ ■ □ □ □ □ □ □ □ □ □ □ □ □ ■ ■
■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■
■ □ □ □ □ □ □ ■ □ □ ■ □ □ □ □ □ □ ■
■ □ □ □ □ □ □ □ ■ ■ □ □ □ □ □ □ □ ■
□ ■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ ■ ■ □ □ □ □ □ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ □ ■
□ □ □ □ ■ ■ □ □ □ □ □ □ ■ ■
□ □ □ □ □ □ ■ ■ ■ ■ ■ ■
#Output5
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ □ □ □ □
□ □ ■ ■ ■ □ □ □ □ □ ■ ■ ■ □ □
□ ■ ■ □ □ □ □ □ □ □ □ □ ■ ■ □
□ ■ □ □ □ □ □ □ □ □ □ □ □ ■ □
■ ■ □ □ □ □ □ □ □ □ □ □ □ ■ ■
■ □ □ □ ■ ■ □ □ □ ■ ■ □ □ □ ■
■ □ □ □ ■ ■ □ □ □ ■ ■ □ □ □ ■
■ □ □ □ □ □ □ □ □ □ □ □ □ □ ■
■ □ □ ■ □ □ □ □ □ □ □ ■ □ □ ■
■ □ □ ■ ■ □ □ □ □ □ ■ ■ □ □ ■
■ ■ □ □ ■ ■ □ □ □ ■ ■ □ □ ■ ■
□ ■ □ □ □ ■ ■ ■ ■ ■ □ □ □ ■ □
□ ■ ■ □ □ □ □ □ □ □ □ □ ■ ■ □
□ □ ■ ■ ■ □ □ □ □ □ ■ ■ ■ □ □
□ □ □ □ ■ ■ ■ ■ ■ ■ ■ □ □ □ □
#파이썬
#저는 가로세로 길이 없이도 문제가 풀려버립니다.
def bitmap_printer(x):
for i in range (len(x)):
x[i]=x[i].split(' ')
if '' in x[i]:
x[i].remove('')
if int(x[i][0])!=0: #첫 숫자가 0이 아닐경우,
for j in range (len(x[i])):
if j%2==0: #짝수번째 □
for k in range (0,int(x[i][j])):
print ('□',end=' ')
else:
for k in range (0,int(x[i][j])):
print ('■', end=' ')
elif int(x[i][0])==0: #첫 숫자가 0일 경우,
for j in range (1,len(x[i])):
if j%2==0: #짝수번째 □
for k in range (0,int(x[i][j])):
print ('□',end=' ')
else:
for k in range (0,int(x[i][j])):
print ('■', end=' ')
print ()
inp1='''1 3 1
4 1
1 4
0 1 3 1
0 1 3 1
1 4'''.split('\n')
bitmap_printer(inp1)
print ()
inp2='''4 11
4 9 2 1
4 9 2 1
4 11
4 9
4 9
5 7
0 17
1 15'''.split('\n')
bitmap_printer(inp2)
print ()
inp3='''6 5 2 3
4 2 5 2 3 1
3 1 9 1 2 1
3 1 9 1 1 1
2 1 11 1
2 1 10 2
2 1 9 1 1 1
2 1 8 1 2 1
2 1 7 1 3 1
1 1 1 1 4 2 3 1
0 1 2 1 2 2 5 1
0 1 3 2 5 2
1 3 2 5'''.split('\n')
bitmap_printer(inp3)
print ()
inp4='''6 2 2 2
5 1 2 2 2 1
6 6
4 2 6 2
3 1 10 1
2 1 12 1
2 1 3 1 4 1 3 1
1 2 12 2
0 1 16 1
0 1 6 1 2 1 6 1
0 1 7 2 7 1
1 1 14 1
2 1 12 1
2 1 5 2 5 1
3 1 10 1
4 2 6 2
6 6'''.split('\n')
bitmap_printer(inp4)
print ()
inp5='''4 7 4
2 3 5 3 2
1 2 9 2 1
1 1 11 1 1
0 2 11 2
0 1 3 2 3 2 3 1
0 1 3 2 3 2 3 1
0 1 13 1
0 1 2 1 7 1 2 1
0 1 2 2 5 2 2 1
0 2 2 2 3 2 2 2
1 1 3 5 3 1 1
1 2 9 2 1
2 3 5 3 2
4 7 4'''.split('\n')
bitmap_printer(inp5)
# ■□
def bitmap(data):
for e, pixel in enumerate(data):
print('#Output{}'.format(e+1))
for i in range(2, len(pixel)):
num = pixel[i].split()
p = ['□'*int(j) if (n+1) % 2 != 0 else '■'*int(j) for n, j in enumerate(num)]
# 굳이 0으로 시작하는지 않하는지 판별할 필요가 없습니다.
print('{}'.format(''.join(p)))
if __name__ == '__main__':
in_txt = open('./bitmap input.txt', 'r').read().split('\n\n') #txt 입력 5개를 5개의 문자열로(줄바꿈) 구분
data = [line.split('\n') for line in in_txt] # 각 예제 별 픽셀 수를 분리
bitmap(data)
#input1
#bitmap = [[1,3,1],[4,1],[1,4],[0,1,3,1],[0,1,3,1],[1,4]]
#input2
#bitmap = [[4,11],[4,9,2,1],[4,9,2,1],[4,11],[4,9],[4,9],[5,7],[0,17],[1,15]]
#input3
#bitmap = [[6,5,2,3],[4,2,5,2,3,1],[3,1,9,1,2,1],[3,1,9,1,2,1],[2,1,11,1],[2,1,10,2],[2,1,9,1,1,1],[2,1,8,1,2,1],[2,1,7,1,3,1],[1,1,1,1,4,2,3,1],[0,1,2,1,2,2,5,1],[0,1,3,2,5,2],[1,3,2,5]]
#input4
bitmap = [[6,2,2,2],[4,2,5,2,3,1],[3,1,9,1,2,1],[3,1,9,1,2,1],[2,1,11,1],[2,1,10,2],[2,1,9,1,1,1],[2,1,8,1,2,1],[2,1,7,1,3,1],[1,1,1,1,4,2,3,1],[0,1,2,1,2,2,5,1],[0,1,3,2,5,2],[1,3,2,5]]
for i in range(len(bitmap)):
for j in range(len(bitmap[i])):
if j%2 == 0:
print('□ '*bitmap[i][j], end = '')
elif j%2 == 1:
print('■ '*bitmap[i][j], end = '')
print()
while(1):
print('#Input' + str(rep))
line = input('height&width: ')
height, width = line.split(' ')
height = int(height)
lines = []
for i in range(height):
my_input = input('')
lines.append(my_input.split(' '))
for line in lines:
if line[0] != '0':
cnt = 1
for b in line:
if cnt % 2 == 1:
print('□'*int(b),end='')
cnt = cnt + 1
else:
print('■' * int(b),end='')
cnt = cnt + 1
print('')
elif line[0] == '0':
cnt = 0
for b in line:
if cnt == 0:
cnt = cnt + 1
pass
if cnt == 1:
print('■'*int(b),end='')
cnt = cnt + 1
else:
if cnt % 2 == 1:
print('□' * int(b),end='')
cnt = cnt + 1
else:
print('■' * int(b),end='')
cnt = cnt + 1
print('')
def sol() :
height_width, inp_map, inp_list = list(map(int, input("height, width").split())), ['□', '■'], []
for col in range(0, height_width[0]) :
inp_list.append(list(map(int, input("INPUT : ").split())))
for col in inp_list :
print(" ".join("".join([inp_map[j%2]*col[j] for j in range(0, len(col))])))
if __name__ == "__main__" :
sol()
결과
INPUT 3
height, width13 18
INPUT : 6 5 2 3
INPUT : 4 2 5 2 3 1
INPUT : 3 1 9 1 2 1
INPUT : 3 1 9 1 1 1
INPUT : 2 1 11 1
INPUT : 2 1 10 2
INPUT : 2 1 9 1 1 1
INPUT : 2 1 8 1 2 1
INPUT : 2 1 7 1 3 1
INPUT : 1 1 1 1 4 2 3 1
INPUT : 0 1 2 1 2 2 5 1
INPUT : 0 1 3 2 5 2
INPUT : 1 3 2 5
□ □ □ □ □ □ ■ ■ ■ ■ ■ □ □ ■ ■ ■
□ □ □ □ ■ ■ □ □ □ □ □ ■ ■ □ □ □ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ ■ □ □ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ ■ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ ■ ■
□ □ ■ □ □ □ □ □ □ □ □ □ ■ □ ■
□ □ ■ □ □ □ □ □ □ □ □ ■ □ □ ■
□ □ ■ □ □ □ □ □ □ □ ■ □ □ □ ■
□ ■ □ ■ □ □ □ □ ■ ■ □ □ □ ■
■ □ □ ■ □ □ ■ ■ □ □ □ □ □ ■
■ □ □ □ ■ ■ □ □ □ □ □ ■ ■
□ ■ ■ ■ □ □ ■ ■ ■ ■ ■
INPUT 4
height, width17 18
INPUT : 6 2 2 2
INPUT : 5 1 2 2 2 1
INPUT : 6 6
INPUT : 4 2 6 2
INPUT : 3 1 10 1
INPUT : 2 1 12 1
INPUT : 2 1 3 1 4 1 3 1
INPUT : 1 2 12 2
INPUT : 0 1 16 1
INPUT : 0 1 6 1 2 1 6 1
INPUT : 0 1 7 2 7 1
INPUT : 1 1 14 1
INPUT : 2 1 12 1
INPUT : 2 1 5 2 5 1
INPUT : 3 1 10 1
INPUT : 4 2 6 2
INPUT : 6 6
□ □ □ □ □ □ ■ ■ □ □ ■ ■
□ □ □ □ □ ■ □ □ ■ ■ □ □ ■
□ □ □ □ □ □ ■ ■ ■ ■ ■ ■
□ □ □ □ ■ ■ □ □ □ □ □ □ ■ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ ■ □ □ □ □ ■ □ □ □ ■
□ ■ ■ □ □ □ □ □ □ □ □ □ □ □ □ ■ ■
■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■
■ □ □ □ □ □ □ ■ □ □ ■ □ □ □ □ □ □ ■
■ □ □ □ □ □ □ □ ■ ■ □ □ □ □ □ □ □ ■
□ ■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ □ □ □ □ □ □ □ ■
□ □ ■ □ □ □ □ □ ■ ■ □ □ □ □ □ ■
□ □ □ ■ □ □ □ □ □ □ □ □ □ □ ■
□ □ □ □ ■ ■ □ □ □ □ □ □ ■ ■
□ □ □ □ □ □ ■ ■ ■ ■ ■ ■
H = int(input('height&width: ').split()[0])
bitmap = ''
for _ in range(H):
white = True
for x in map(int, input().split()):
bitmap += ('□ ' if white else '■ ') * x
white = not white
bitmap += '\n'
print(bitmap)
w, h = 6, 6
pixels = '''
1 3 1
4 1
1 4
0 1 3 1
0 1 3 1
1 4
'''
lPixels = pixels.split('\n')
for line in lPixels:
if line == '':
continue
else:
px = line.split(' ')
i = 0
bFirstBlack = False
for p in px:
output = ''
# print(p)
p = int(p)
if True == bFirstBlack:
bFirstBlack = False
output = '■ ' * p
else:
if i == 0 and p == 0:
bFirstBlack = True
i = i + 1
continue
elif (i + 1) % 2 == 0:
output = '■ ' * p
else:
output = '□ ' * p
print(output , end='')
i = i + 1
print('\n')
Python 3.8
print('\n'.join([''.join([('□ ' if index % 2 == 0 else '■ ') * int(value) for index, value in enumerate(input().strip().split())]) for i in range(int(input('Height: ').strip()))]))
hw=input('height&width: ')
h= int(hw.split()[0])
w= int(hw.split()[1])
L=[]
while len(L)!=h:
a=input('> ')
L.append(a)
L=[L[i] for i in range(len(L))]
L=[i.split() for i in L]
for i in range(len(L)):
L[i]=[int(j) for j in L[i]]
def bit2(L1):
printlist=[]
for i in range(len(L1)):
if i%2!=0:
printlist.append(L1[i]*'■')
else:
printlist.append(L1[i]*'□')
for p in printlist:
print(p, end='')
print("")
def bit1(L1):
printlist=[]
for i in range(len(L1)):
if i%2==0:
printlist.append(L1[i]*'□')
else:
printlist.append(L1[i]*'■')
for p in printlist:
print(p, end='')
print("")
for i in L:
if i[0]!=0:
bit1(i)
else:
bit2(i)
푸는 동안 정말 즐거웠습니다 좋은 문제 감사합니다!
height = input('Enter an height: ')
width = input('Enter an width: ')
arrays = []
for n in range(0, int(height)):
arr = input("Enter an integer array with ' ': ").split(' ')
arr = list(map(int, arr))
assert sum(arr) <= int(width), 'The sum of array can not be greater than {}'.format(width)
arrays.append(arr)
for arr in arrays:
arr2bit = []
for i, n in enumerate(arr):
if i == 0 and n == 0:
pass
else:
if i % 2 == 0:
arr2bit.append(n * '□')
else:
arr2bit.append(n * '■')
m = ''
for b in arr2bit:
m += b
print(m)
function bitmapPrint(matrix, inputString) {
let result = '';
const rows = inputString.split('\n');
rows.forEach( (element, i) => {
let inputCol = 0;
element.split(' ').forEach( (e, j) => {
for(let k=0; e>k; k++) {
result = result + ((j % 2) === 0 ? '□' : '■'); // matrix[i][inputCol++] = ((j % 2) === 0 ? '□' : '■');
}
})
result = result + '\n';
});
console.log(result); // console.log(matrix);
}
function matrix(rows, cols, defaultValue){
var arr = [];
for(let i=0; i < rows; i++){
arr.push([]);
arr[i].push( new Array(cols));
for(let j=0; j < cols; j++){
arr[i][j] = defaultValue;
}
}
return arr;
}
bitmapPrint(matrix(6,6), `1 3 1
4 1
1 4
0 1 3 1
0 1 3 1
1 4`);
bitmapPrint(matrix(9,18), `4 11
4 9 2 1
4 9 2 1
4 11
4 9
4 9
5 7
0 17
1 15`);
bitmapPrint(matrix(13,18), `6 5 2 3
4 2 5 2 3 1
3 1 9 1 2 1
3 1 9 1 1 1
2 1 11 1
2 1 10 2
2 1 9 1 1 1
2 1 8 1 2 1
2 1 7 1 3 1
1 1 1 1 4 2 3 1
0 1 2 1 2 2 5 1
0 1 3 2 5 2
1 3 2 5`);
bitmapPrint(matrix(17,18), `6 2 2 2
5 1 2 2 2 1
6 6
4 2 6 2
3 1 10 1
2 1 12 1
2 1 3 1 4 1 3 1
1 2 12 2
0 1 16 1
0 1 6 1 2 1 6 1
0 1 7 2 7 1
1 1 14 1
2 1 12 1
2 1 5 2 5 1
3 1 10 1
4 2 6 2
6 6`);
bitmapPrint(matrix(15,15), `4 7 4
2 3 5 3 2
1 2 9 2 1
1 1 11 1 1
0 2 11 2
0 1 3 2 3 2 3 1
0 1 3 2 3 2 3 1
0 1 13 1
0 1 2 1 7 1 2 1
0 1 2 2 5 2 2 1
0 2 2 2 3 2 2 2
1 1 3 5 3 1 1
1 2 9 2 1
2 3 5 3 2
4 7 4`);
x = input("height & width: ").split(" ")
result = ""
for i in range(int(x[0])):
temp = input().split(" ")
for k in range(len(temp)):
if k % 2 == 0:
result += "□ " * int(temp[k])
else:
result += "■ " * int(temp[k])
result += "\n"
print(result)
import random
#h = height w = weigth
h,w = map(int,input('높이 넓이 : ').split())
dot = ''
for x in range(h):
l = []
while 1:
l.append(random.randint(0,w))
if sum(l)>w :
l.pop()
break
for i in range(len(l)):
if i%2==1 : dot += ('□'*l[i])
else : dot += ('■'*l[i])
dot += '\n'
print(dot)
input1 = '''1 3 1
4 1
1 4
0 1 3 1
0 1 3 1
1 4'''.split('\n')
for i in range(len(input1)):
input1[i] = input1[i].split(' ')
if int(input1[i][0]) != 0:
for j in range(len(input1[i])):
if j % 2 == 0:
print('□'*int(input1[i][j]), end='')
else:
print('■'*int(input1[i][j]), end='')
else:
for j in range(1,len(input1[i])):
if j % 2 == 0:
print('□'*int(input1[i][j]),end='')
else:
print('■'*int(input1[i][j]), end='')
print()
a = input("height&width:")
h = int(a[0])
w = int(a[2])
codearr=[]
for i in range(h):
while True:
print(i+1,'번째',end=' ')
b = list(map(int,input('비트맵 코드 입력: ').split(" ")))
if sum(b) <= w:
codearr.append(b)
break
for i in codearr:
for k in range(len(i)) :
if k%2==0:
print('□ '*i[k],end='')
else:
print('■ '*i[k],end='')
print('')
inp = '''9 18
4 11
4 9 2 1
4 9 2 1
4 11
4 9
4 9
5 7
0 17
1 15'''
res, *data = inp.splitlines()
for datum in data:
line=''
for i,d in enumerate(datum.split(' ')):
if i%2 == 0:
line = line + '□ '*int(d)
else:
line = line + '■ '*int(d)
print(line)
def bitmapPrinter(h, map):
for r in range(h):
for c in range(len(map[r])):
if c % 2 == 0:
munja = '□'
else:
munja = '■'
for x in range(map[r][c]):
print(munja, end=' ')
print()
height, width = 6, 6
map = [[1, 3, 1], [4, 1], [1, 4], [0, 1, 3, 1], [0, 1, 3, 1], [1, 4]]
bitmapPrinter(height, map)
print(' =' * 10)
height, width = 9, 10
map = [[4, 11], [4, 9, 2, 1], [4, 9, 2, 1], [4, 11],
[4, 9], [4, 9], [5, 7], [0, 17], [1, 15]]
bitmapPrinter(height, map)
print(' =' * 10)
### 입력 반을 때
# map = []
# (height, width) = (int(x) for x in input('height와 width 입력하세요.: ').split())
# for h in range(height):
# inputSu = list(int(x) for x in input('Bitmap의 {0}번째 라인수 입력: \n'.format(h+1)).split())
# map.append(inputSu)
# bitmapPrinter(height, map)
# print(' =' * 10)