[코테] 백준 시뮬레이션과 구현 2290번 문제
2290번 : LCD Test
문제 링크
https://www.acmicpc.net/problem/2290
문제 설명
지민이는 새로운 컴퓨터를 샀다. 하지만 새로운 컴퓨터에 사은품으로 온 LC-디스플레이 모니터가 잘 안나오는 것이다. 지민이의 친한 친구인 지환이는 지민이의 새로운 모니터를 위해 테스트 할 수 있는 프로그램을 만들기로 하였다.
입력
첫째 줄에 두 개의 정수 s와 n이 들어온다. (1 ≤ s ≤ 10, 0 ≤ n ≤ 9,999,999,999)이다. n은 LCD 모니터에 나타내야 할 수 이며, s는 크기이다.
출력
길이가 s인 ‘-‘와 ‘|’를 이용해서 출력해야 한다. 각 숫자는 모두 s+2의 가로와 2s+3의 세로로 이루어 진다. 나머지는 공백으로 채워야 한다. 각 숫자의 사이에는 공백이 한 칸 있어야 한다.
문제풀이
각 숫자를 표시하기 위한 함수 만들고, 입력받은 숫자가 2개 이상이면 붙이는 작업까지 완성하면 된다. 시간이 걸릴 뿐 어렵지는 않은 문제이다.
def one (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) != 0 and j == width-1 :
list[i][j] = '|'
return list
def two (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and j == width-1 :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and j == 0 :
list[i][j] = '|'
return list
def three (s: int) -> list :
width, height = s+2, s*2 + 3
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and j == width-1 :
list[i][j] = '|'
return list
def four (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i == height//2 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and (j == width-1 or j == 0) :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and j == width-1 :
list[i][j] = '|'
return list
def five (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and j == 0 :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and j == width-1 :
list[i][j] = '|'
return list
def six (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and j == 0 :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and (j == width-1 or j == 0):
list[i][j] = '|'
return list
def seven (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) != 0 and j == width-1 :
list[i][j] = '|'
elif i == 0 and 0 < j < width-1 :
list[i][j] = '-'
return list
def eight (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and (j == width-1 or j == 0) :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and (j == width-1 or j == 0):
list[i][j] = '|'
return list
def nine (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and (j == width-1 or j == 0) :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and j == width-1 :
list[i][j] = '|'
return list
def zero (s: int) -> list :
list = [[' ' for _ in range(width)] for _ in range(height)]
for i in range(height) :
for j in range(width) :
if i % (s+1) == 0 and 0 < j < width-1 and i != height//2 :
list[i][j] = '-'
elif i % (s+1) != 0 and i < s+1 and (j == width-1 or j == 0) :
list[i][j] = '|'
elif i % (s+1) != 0 and i > s+1 and (j == width-1 or j == 0):
list[i][j] = '|'
return list
s, n = input().split()
s = int(s)
width, height = s+2, s*2 + 3
blank = [[' ' for _ in range(1)] for _ in range(height)]
stacked = []
for num in n :
if num == '0' :
temp = zero(s)
elif num == '1' :
temp = one(s)
elif num == '2' :
temp = two(s)
elif num == '3' :
temp = three(s)
elif num == '4' :
temp = four(s)
elif num == '5' :
temp = five(s)
elif num == '6' :
temp = six(s)
elif num == '7' :
temp = seven(s)
elif num == '8' :
temp = eight(s)
elif num == '9' :
temp = nine(s)
if len(stacked) == 0 :
stacked = temp
else :
stacked = [row1 + row2 for row1, row2 in zip(stacked, blank)]
stacked = [row1 + row2 for row1, row2 in zip(stacked, temp)]
for i in range(len(stacked)) :
for j in range(len(stacked[0])) :
print(stacked[i][j], end='')
print()
Comments