๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/Kotlin

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค • ์ฝ”ํ‹€๋ฆฐ] ์ฝœ๋ผ ๋ฌธ์ œ #132267

by ํ‚ค์œค 2023. 12. 13.

#132267

๐ŸŽ„ Question ?

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

class Solution {
    fun solution(a: Int, b: Int, n: Int): Int {
        var answer: Int = 0
        return answer
    }
}

๐Ÿงฉ Thought Process

  1. while๋ฌธ ์•ˆ์—์„œ ๋งค๋ฒˆ ๋‚˜๋ˆ„์–ด์ฃผ๊ณ  ๋ชซ ๋”ํ•ด์ฃผ๊ธฐ

 

๐ŸŽ€ Answer

class Solution {
    fun solution(a: Int, b: Int, n: Int): Int {
        var answer: Int = 0
        var bottleNumber: Int = n
        var remainder: Int = 0
        while (bottleNumber>=a) {            
            answer += (bottleNumber/a)*b
            remainder = (bottleNumber%a)
            bottleNumber = (bottleNumber/a)*b + remainder
        }
        return answer
    }
}

 

๐ŸŽ Result

๐Ÿ† Comment

๋‚˜๋ˆ—์…ˆ์ด๋ž‘ ๊ณฑ์…ˆ ์ˆœ์„œ ์ž˜๋ชป ์ ์–ด์„œ ์˜ค๋ž˜๊ฑธ๋ฆผ. ๋‚˜๋ˆ—์…ˆ ํ•˜๋ฉด ๋‚˜๋จธ์ง€๋ฅผ ๋ฒ„๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜๋ˆ—์…ˆ์„ ์–ธ์ œ ํ•˜๋ƒ์— ๋”ฐ๋ผ ๊ฐ’์ด ๋ฐ”๋€œ.