Skip to content

Commit 5398244

Browse files
committed
[BOJ] #6603. 로또 / 실버2 / 20분 / 성공
1 parent 50081d2 commit 5398244

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
"""
5+
#6603. 로또
6+
백트래킹 풀이
7+
"""
8+
9+
def backtrack(lotto, current):
10+
if len(lotto) == 6: # 종료조건
11+
print(' '.join(map(str, lotto)))
12+
return
13+
14+
for i in range(current, k):
15+
lotto.append(S[i])
16+
backtrack(lotto, i+1)
17+
lotto.pop()
18+
19+
20+
while True:
21+
testcase = input().strip()
22+
if testcase == '0':
23+
break
24+
nums = list(map(int, testcase.split()))
25+
k, S = nums[0], nums[1:]
26+
27+
backtrack([], 0)
28+
print()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
from itertools import combinations
3+
input = sys.stdin.readline
4+
5+
"""
6+
#6603. 로또
7+
조합 풀이
8+
"""
9+
10+
while True:
11+
testcase = input().strip()
12+
if testcase == '0':
13+
break
14+
nums = list(map(int, testcase.split()))
15+
k, S = nums[0], nums[1:]
16+
combs = list(combinations(S, 6))
17+
for comb in combs:
18+
print(' '.join(map(str, comb)))
19+
print()

0 commit comments

Comments
 (0)