[Python3] 백준 6603번 - 로또 풀이 (조합)

돌멩이·2024년 8월 19일
0

알고리즘

목록 보기
13/17

📌 문제 정보

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

유형: 조합

난이도: 실버2

스스로 풀었는가? ✅




💻 작성 코드

import sys
from itertools import combinations

readline = sys.stdin.readline
input = readline().rstrip('\n')
while input != '0':
    arr = list(map(int, input.split()))
    k = arr[0]
    arr = arr[1:]
    LOTTO_LEN = 6
    combs = combinations(arr, LOTTO_LEN)
    for comb in combs:
        output = ' '.join(map(str, comb))
        print(output)
    print()
    input = readline().rstrip('\n')



🎯 접근 방식

  1. input으로 0이 들어올 때까지 반복적으로 배열을 입력 받는다.
  2. 배열에서 6인 조합들을 만들어 출력한다.



💡 개선사항

  1. 변수를 한 줄에 할당할 수 있다. k, numbers = arr[0], arr[1:]



이 문제를 풀면서 파이썬에는 do-while 문이 없다는 걸 알았다..

[ktb-algorithm-study] 2주차

profile
하나를 배웠을 때 하나를 알면 잘하는 것이다. 💡

0개의 댓글