249. 성냥개비

아현·2021년 8월 13일
0

Algorithm

목록 보기
261/400

백준




1. Python


import sys
input = sys.stdin.readline
 
d = [0,0,1,7,4,2,6,8,10,18,22]
 
def getMax(n):
    ret = [1 for i in range(n // 2)]
    if n & 1: #last digit is 1
        ret[0] = 7
    return ret
 
def getMin(n):
    ret = [8 for i in range((n + 6)//7)] #7이 가장 많이 사용할 수 있다
    if n % 7 == 1: 
        ret[0] = 1
        ret[1] = 0
    if n % 7 == 2: 
        ret[0] = 1
    if n % 7 == 3: 
        ret[0] = 2
        ret[1] = 0
        ret[2] = 0
    if n % 7 == 4: 
        ret[0] = 2
        ret[1] = 0
    if n % 7 == 5: 
        ret[0] = 2
    if n % 7 == 6: 
        ret[0] = 6
    return ret
 
for _ in range(int(input())):
    n = int(input())
    if n < 11:
        print(d[n],end=" ")
    else:
        print(*getMin(n),sep='',end=' ')

    print(*getMax(n),sep='')


profile
Studying Computer Science

0개의 댓글