황소개발자
백준 6603 파이썬 python : 로또 - combination 직접구현 본문
반응형
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()
반응형
'백준 문제 풀이' 카테고리의 다른 글
백준 1182 파이썬 python : 부분수열의 합 @@황소처럼 우직하게@@ (0) | 2020.02.28 |
---|---|
백준 1759 파이썬 python : 암호 만들기 @@황소처럼 우직하게@@ 코로나 조심하세요 (0) | 2020.02.28 |
백준 10971 파이썬 python : 외판원 순회 2 @@황소처럼 우직하게@@ 아주나이쑤 (0) | 2020.02.28 |
백준 10819 파이썬 python : 차이를 최대로 @@황소처럼 우직하게@@ 볼륨 쵀돼료! (0) | 2020.02.28 |
백준 10974 파이썬 python : 모든 순열 @@황소처럼 우직하게@@ permutations 구현할 때, 이 코드 참고하세요~ (0) | 2020.02.28 |
Comments