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

Algorithm/Baekjoon

[๋ฐฑ์ค€] (Swift) 4796๋ฒˆ - ์บ ํ•‘ (feat. ๊ทธ๋ฆฌ๋””)

๊ฐ์ž ๐Ÿฅ” 2023. 2. 1. 16:06
๋ฐ˜์‘ํ˜•

์นœ๊ตฌ๋“ค๊ณผ ๋ฌธ์ œ๋ฅผ ๋นก์„ธ๊ฒŒ ํ’€๊ธฐ ์œ„ํ•ด ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์Šคํ„ฐ๋””๋ฅผ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋งŽ๊ด€๋ถ€

https://github.com/HotCodeBreakers/CodingTest

 

GitHub - HotCodeBreakers/CodingTest

Contribute to HotCodeBreakers/CodingTest development by creating an account on GitHub.

github.com

 

๐ŸŸฃ ๋ฌธ์ œ

https://www.acmicpc.net/problem/4796

 

4796๋ฒˆ: ์บ ํ•‘

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , L, P, V๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค. ๋ชจ๋“  ์ž…๋ ฅ ์ •์ˆ˜๋Š” int๋ฒ”์œ„์ด๋‹ค. ๋งˆ์ง€๋ง‰ ์ค„์—๋Š” 0์ด 3๊ฐœ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

 

๐ŸŸฃ ๋‚˜์˜ ํ’€์ด

์‰ฌ์šด ๋ฌธ์ œ๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์ž๋งˆ์ž ๋ฐ”๋กœ ์ƒ๊ฐ์ด ๋‚ฌ๋‹ค! ์ˆ˜ํ•™์ ์ธ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•ด์„œ ํ’€์—ˆ๋‹ค.
์—ฌ๊ธฐ์„œ ์ฃผ์˜ํ• ์ ์€, ์˜ˆ์™ธ์‚ฌํ•ญ์„ ์ƒ๊ฐํ•ด ์ฃผ์–ด์•ผํ•œ๋‹ค. 

์˜ˆ์ œ์—๋Š” ์—†์ง€๋งŒ, [ 2, 8, 23 ] ๊ณผ ๊ฐ™์€ ์ž…๋ ฅ์ด ๋“ค์–ด์™”๋‹ค๋ฉด, 23์„ 8๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€ 7์€ 2๋ณด๋‹ค ํฌ๊ธฐ ๋•Œ๋ฌธ์—, 7์„ ๊ทธ๋Œ€๋กœ ๋”ํ•ด์ฃผ๋ฉด ์•ˆ๋œ๋‹ค! 2๋ฅผ ๋”ํ•ด์ฃผ์–ด์•ผํ•œ๋‹ค. 

๋งŒ์•ฝ [7, 8, 22] ๊ฐ€ ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์กŒ๋‹ค๋ฉด, 22๋ฅผ 8๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€ 6์€ 7๋ณด๋‹ค ์ž‘๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” 6๋ฒˆ ๋” ์บ ํ•‘์„ ๊ฐˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, 7์„ ๋”ํ•ด์ฃผ๋ฉด ์•ˆ๋˜๊ณ  ๋‚˜๋จธ์ง€์ธ 6์„ ๋”ํ•ด์ฃผ์–ด์•ผํ•œ๋‹ค. ์ด ์กฐ๊ฑด์„ ์ž˜ ์ƒ๊ฐํ•˜๊ณ  ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด ์™„๋ฃŒ!

๐ŸŸฃ ์ •๋‹ต์ฝ”๋“œ

import Foundation

var count = 0

while let input = readLine() {
    if input == "0 0 0" {
        break
    }

    let lpv = input.split(separator: " ").map{ Int($0)! }
    let l = lpv[0]
    let p = lpv[1]
    let v = lpv[2]
    count += 1


    print("Case \(count): \(((v/p)*l) + (min(l, v%p)))")
}
๋ฐ˜์‘ํ˜•