Skip to content

Commit 97f454c

Browse files
committed
WeeklyChallenge: WeeklyChallenge 과제 문제(#6603. 로또) 정답 코드 추가
1 parent a74e1a5 commit 97f454c

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

_WeeklyChallenges/W19-[Graph-Backtracking]/Assignment_BOJ_6603_로또.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,49 @@
44
유형: Graph, Backtracking
55
"""
66

7-
# 토요일에 업로드 예정
7+
"""
8+
#6603. 로또
9+
백트래킹 풀이
10+
"""
11+
import sys
12+
input = sys.stdin.readline
13+
def backtrack(lotto, current):
14+
if len(lotto) == 6: # 종료조건
15+
print(' '.join(map(str, lotto)))
16+
return
17+
18+
for i in range(current, k):
19+
lotto.append(S[i])
20+
backtrack(lotto, i+1)
21+
lotto.pop()
22+
23+
24+
while True:
25+
testcase = input().strip()
26+
if testcase == '0':
27+
break
28+
nums = list(map(int, testcase.split()))
29+
k, S = nums[0], nums[1:]
30+
31+
backtrack([], 0)
32+
print()
33+
34+
35+
"""
36+
#6603. 로또
37+
조합 풀이
38+
"""
39+
import sys
40+
from itertools import combinations
41+
input = sys.stdin.readline
42+
43+
while True:
44+
testcase = input().strip()
45+
if testcase == '0':
46+
break
47+
nums = list(map(int, testcase.split()))
48+
k, S = nums[0], nums[1:]
49+
combs = list(combinations(S, 6))
50+
for comb in combs:
51+
print(' '.join(map(str, comb)))
52+
print()

0 commit comments

Comments
 (0)