Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์œ„ํด๋ฆฌ์ฑŒ๋ฆฐ์ง€(1์ฃผ์ฐจ) - ๋ถ€์กฑํ•œ ๊ธˆ์•ก ๊ณ„์‚ฐํ•˜๊ธฐ

๊ฐ์ž ๐Ÿฅ” 2021. 8. 6. 19:17
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ๋งํฌ

 

๋ฌธ์ œํ’€์ด

  1. countํšŸ์ˆ˜๋ฅผ price์— ๊ณฑํ•ด์ฃผ๋ฉด์„œ total์„ ๊ตฌํ•˜๊ณ 
  2. money์™€์˜ ์ฐจ๋ฅผ ๊ตฌํ•œ๋‹ค.
  3. ์ฐจ์ด๊ฐ€ ๋งˆ์ด๋„ˆ์Šค๊ฐ€ ๋‚˜์˜ค๋ฉด, ๋ˆ์ด ๋ถ€์กฑํ•˜์ง€ ์•Š๋‹ค๋Š” ๋œป์ด๋ฏ€๋กœ 0์„ ๋ฆฌํ„ดํ•œ๋‹ค.
def solution(price, money, count):
    
    # ๋‚ด์•ผ ํ•  ์ด ๊ธˆ์•ก
    total = 0
    for i in range(1,count+1):
        total += (price*i)
    
    result = total - money
    
    if result < 0 :
        result = 0
    
    return result

 

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

๊ฐ„๋‹จํ•˜๋‹ค๊ณ  ์งฏ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์ง€๋งŒ, ๋‹จ์ˆœํ•œ ์‚ฐ์ˆ ํ‰๊ท ์„ ์ด์šฉํ•ด์„œ ํ‘ผ ์‚ฌ๋žŒ๋“ค์˜ ํ’€์ด๊ฐ€ ๋ˆˆ์— ๋„์—ˆ๋‹ค.
๊ทธ๋ ‡๊ฒŒ ํ•˜๊ฒŒ ๋˜๋ฉด ์‹œ๊ฐ„ ๋ณต์žก๋„๋„ ๊ต‰์žฅํžˆ ์ค„์–ด๋“ค๊ณ , ๋น ๋ฅธ ์—ฐ์‚ฐ์ด ๊ฐ€๋Šฅํ•  ๊ฒƒ๊ฐ™๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋‚˜๋Š” total ๊ณผ money์˜ ์ฐจ๋ฅผ result๋กœ ๋”ฐ๋กœ ๊ตฌํ–ˆ์ง€๋งŒ, ์–ด์ฐจํ”ผ ํ•œ์ •๋œ money์•ˆ์—์„œ ๋ถ€์กฑํ•œ์ง€ ๋ถ€์กฑํ•˜์ง€ ์•Š์€์ง€๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— money์—์„œ ์‚ฌ์šฉํ•œ ๊ธˆ์•ก์„ ๋นผ๋‚˜๊ฐ€๋Š” ๊ฒƒ์ด ๋ณ€์ˆ˜๊ฐ€ ๋” ์ค„์–ด๋“ค๊ณ  ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋” ํšจ์œจ์ ์ผ ๊ฒƒ ๊ฐ™๋‹ค.

๋ฐ˜์‘ํ˜•