황소개발자

백준 6603 파이썬 python : 로또 - combination 직접구현 본문

백준 문제 풀이

백준 6603 파이썬 python : 로또 - combination 직접구현

hjp845 2020. 2. 28. 12:16
반응형
import sys
input = sys.stdin.readline

def next_permutation(lst):
    n = len(lst)
    i = n - 1
    while i > 0 and lst[i - 1] >= lst[i]:
        i -= 1
    if i == 0:
        return [-1]
    j = n - 1
    while lst[i - 1] >= lst[j]:
        j -= 1
    tmp = lst[j]
    lst[j] = lst[i - 1]
    lst[i - 1] = tmp
    lst = lst[:i] + sorted(lst[i:])
    return lst


while True:
    s = input().strip()
    if s == '0':
        break
    lst = list(map(int, s.split()))
    n = lst[0]
    lst = lst[1:]
    bit = [0] * (n - 6) + [1] * 6
    bites = []
    while True:
        if bit == [-1]:
            break
        bites = [bit.copy()] + bites
        bit = next_permutation(bit)


    for bit_one in bites:
        lotto = []
        for idx, x in enumerate(bit_one):
            if x == 1:
                lotto.append(lst[idx])
        print(' '.join(map(str, lotto)))
    print()

 

반응형
Comments