[201018] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๊ธฐ๋Šฅ๊ฐœ๋ฐœ

2020. 10. 20. 15:59ใ†๐Ÿ”ฑ Algorithm

ํ’€์ด

  1. rest ๋ฆฌ์ŠคํŠธ ๊ฐ€์žฅ ์•ž์˜ ์›์†Œ(๊ธฐ์ค€ ์›์†Œ)์™€ ๋’ค์˜ ์›์†Œ๋“ค์„ ๋น„๊ต
  2. ์ž์‹ ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€๊ฒŒ ๋‚˜์˜ฌ ๋•Œ ๊นŒ์ง€ ๊ณ„์† ๋น„๊ต (count += 1)
  3. ๊ธฐ์ค€ ์›์†Œ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€๊ฒŒ ๋‚˜์˜ค๋ฉด, rest ๋ฆฌ์ŠคํŠธ ์Šฌ๋ผ์ด์‹ฑ
  4. try ~ except ๊ตฌ๋ฌธ์œผ๋กœ, IndexError ํšŒํ”ผ
progresses = [93,30,55]
speeds = [1,30,5]

import math
def solution(progresses, speeds):
    rest = [math.ceil((100 - p)/s) for p,s in zip(progresses, speeds)]
    count, i = 1, 1
    answer = []
    while rest:
        try:
            if rest[0] >= rest[i]:
                count += 1
                i += 1
            else:
                rest = rest[i:]
                answer.append(count)
                count, i = 1, 1
        except IndexError:
            answer.append(count)
            break
    return answer

# try ~ except ๋‚ด๋ถ€์— if ~ else ๊ตฌ๋ฌธ ์‚ฌ์šฉ
# ๋ฆฌ์ŠคํŠธ ์Šฌ๋ผ์ด์‹ฑ,