Coding Test/programmers

[프로그래머스] 로또의 최고 순위와 최저 순위

Karla Ko 2023. 8. 24. 15:49
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/77484

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

분석

  • 최대한 맞추는 경우 : 0의 개수 + 일치 개수
  • 최소한 맞추는 경우 : 일치 개수
당첨 번호 31 10 45 1 6 19 결과
최고 순위 번호 31 0→10 44 1 0→6 25 4개 번호 일치, 3등
최저 순위 번호 31 0→11 44 1 0→7 25 2개 번호 일치, 5등

 

풀이

def solution(lottos, win_nums):
    
    c = 0
    for i in lottos:
        if i in win_nums:
            c+=1
  
    rank=[6,6,5,4,3,2,1]
    return rank[lottos.count(0)+c],rank[c]

 

 

728x90