코딩 테스트(Python)/백준, 프로그래머스
프로그래머스) 로또의 최고 순위와 최저 순위
5_hyun
2022. 3. 25. 01:33
반응형
https://programmers.co.kr/learn/courses/30/lessons/77484
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
내 풀이(맞음)
def solution(lottos, win_nums):
answer = []
chk = []
count = 0
for i in lottos:
if i == 0:
count += 1
if i in win_nums:
chk.append(i)
for i in chk:
del lottos[lottos.index(i)]
del win_nums[win_nums.index(i)]
t = len(chk) #이게 최소 값
if t+count == 6:
answer.append(1)
elif t+count == 5:
answer.append(2)
elif t+count == 4:
answer.append(3)
elif t+count == 3:
answer.append(4)
elif t+count == 2:
answer.append(5)
else:
answer.append(6)
if t == 6:
answer.append(1)
elif t == 5:
answer.append(2)
elif t == 4:
answer.append(3)
elif t == 3:
answer.append(4)
elif t == 2:
answer.append(5)
else:
answer.append(6)
return answer
chk에 같은 숫자를 넣고 count에는 0의 개수를 넣었다. 그리고 lottos와 win_nums 둘 다 chk로 겹치는 수를 제거해줬다. 그러면 len(chk)는 최소 등수의 개수이다. 그리고 len(chk)에 count를 더하면 이게 최고 등수의 개수가 나온다.
반응형