ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค [lv1] ๋กœ๋˜์˜์ตœ๊ณ ์ˆœ์œ„์™€์ตœ์ €์ˆœ์œ„ ํŒŒ์ด์ฌ

2021. 5. 18. 00:57ใ†๐Ÿ”ฑ Algorithm/Else

2021 dev-matching์— ๋‚˜์˜จ ๋ฌธ์ œ์ธ๋ฐ, ๋Œ€ํšŒ ๋‹น์‹œ์—๋Š” ํ•˜๋‚˜์˜ ์ผ€์ด์Šค๋กœ ์ธํ•ด ํ†ต๊ณผํ•˜์ง€ ๋ชปํ–ˆ๋‹ค. 

14๋ฒˆ ์ผ€์ด์Šค๊ฐ€ ๋ฌธ์ œ์ธ๋ฐ, ์šฐ์„  ์˜ค๋‹ต์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด์ž.

 

์˜ค๋‹ต ์ฝ”๋“œ

def solution(lottos, win_nums):
    count_zero = lottos.count(0)
    count = [1 for num in lottos if num in win_nums]

    if not count:
        return [1, 6]

    return [7 - (len(count) + count_zero), 7 - len(count)]

 ํ•˜๋‚˜๋„ ๋งž์€๊ฒŒ ์—†๋‹ค๋Š” ๊ฒƒ(count ๊ฐ€ 0)์€ 2๊ฐ€์ง€๋กœ ๋ถ„๋ฅ˜ ๋˜๋Š”๋ฐ,

  1. lottos๊ฐ€ ๋ชจ๋‘ 0์ผ ๋• [1,6]์ด ๋˜๊ณ ,
  2. lottos์— 0์ด ํ•˜๋‚˜๋„ ์—†์„ ๋•, [6,6]์ด ๋œ๋‹ค.

์ด ์ ์„ ๊ฐ„๊ณผํ•˜์—ฌ 14๋ฒˆ ์ผ€์ด์Šค๋ฅผ ๋šซ์ง€ ๋ชปํ–ˆ๋‹ค. (1๋ฒˆ ์ผ€์ด์Šค๋งŒ ์ƒ๊ฐํ•œ๊ฑฐ์ง€)

 

 

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— 2๋ฒˆ์˜ ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ๋ฉด ํ†ต๊ณผํ•  ์ˆ˜ ์žˆ๋‹ค.

์ •๋‹ต ์ฝ”๋“œ

def solution(lottos, win_nums):
    count_zero = lottos.count(0)
    count = [1 for num in lottos if num in win_nums]
    if (count_zero) == 6:
        return [1, 6]
    elif not count:
        return [6, 6]
    else:
        return [7 - (len(count) + count_zero), 7 - len(count)]

 

 

๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด 

ํ›จ์”ฌ ์ง๊ด€์ ์ด๊ณ , lottos๋ฅผ win_nums์— ๋งž์ถ”๋Š” ๊ฒƒ์ด ์•„๋‹Œ ๊ทธ ์—ญ์œผ๋กœ ์ ‘๊ทผํ–ˆ๋‹ค.

def solution(lottos, win_nums):

    rank=[6,6,5,4,3,2,1]

    cnt_0 = lottos.count(0)
    ans = 0
    for x in win_nums:
        if x in lottos:
            ans += 1
    return rank[cnt_0 + ans],rank[ans]