m1ndy5's coding blog

[수학] 백준 6603번 로또 with Python 본문

알고리즘 with python/수학

[수학] 백준 6603번 로또 with Python

정민됴 2023. 3. 12. 16:02

https://www.acmicpc.net/problem/6603

pair = []

def comb(start, lotto):
    if len(pair) == 6:
        print(' '.join(str(s) for s in pair))
        return

    for i in range(start, len(lotto)):
        pair.append(lotto[i])
        comb(i+1, lotto)
        pair.pop()

while True :
    lotto = list(map(int, input().split()))

    if lotto[0] == 0:
        break

    comb(0, lotto[1:])
    print()

nCr문제였다!
이전의 Combination 코드에서 개수를 지정하는 len(pair) == 6 일때 return을 해주면 되는 문제였다.
로또에서 1 2 3 4 5 6 이나 6 5 4 3 2 1 이나 똑같기 때문에 Combination이라는 것이 키포인트였다.