프로그래밍 자료/Python

[파이썬] 설탕과자 뽑기

미친사람 2021. 11. 16. 20:08
반응형

코드업 홈페이지 문제 풀이 기록

 

h, w = map(int, input().split())
n = int(input())

m = []

for i in range(h):
  m.append([])
  for j in range(w):
    m[i].append(0)

for i in range(n):
  l, d, x, y = map(int, input().split())
  x -= 1
  y -= 1

  for j in range(l):
    if d == 0:
      m[x][y+j] = 1
    else:
      m[x+j][y] = 1

for i in range(len(m)):
  for j in range(len(m[i])):
    print(m[i][j], end=" ")
  print()

 

짧게

h, w = map(int, input().split())
n = int(input())

m = [[0] * w for i in range(h)]

for i in range(n):
  l, d, x, y = map(int, input().split())
  x -= 1
  y -= 1

  for j in range(l):
    if d == 0:
      m[x][y+j] = 1
    else:
      m[x+j][y] = 1

for i in range(len(m)):
  for j in range(len(m[i])):
    print(m[i][j], end=" ")
  print()
반응형