Bibi's DevLog ๐Ÿค“๐ŸŽ

[๋ฐฑ์ค€ 9469, 14924] ํฐ ๋…ธ์ด๋งŒ, ํฐ ๋…ธ์ด๋งŒ๊ณผ ํŒŒ๋ฆฌ (Swift) ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด Swift

[๋ฐฑ์ค€ 9469, 14924] ํฐ ๋…ธ์ด๋งŒ, ํฐ ๋…ธ์ด๋งŒ๊ณผ ํŒŒ๋ฆฌ (Swift)

๋น„๋น„ bibi 2022. 12. 9. 12:13

14924๋ฒˆ: ํฐ ๋…ธ์ด๋งŒ๊ณผ ํŒŒ๋ฆฌ

9469๋ฒˆ: ํฐ ๋…ธ์ด๋งŒ

  • ์ฒ˜์Œ ํ’€๋ ค๋˜ ๋ฌธ์ œ๋Š” 9469๋ฒˆ์ด๊ณ , ๋ฌดํ•œ๊ธ‰์ˆ˜ ์ด์•ผ๊ธฐ๊ฐ€ ๋‚˜์˜ค๊ธธ๋ž˜ โ€˜์ด๊ฑด ์ˆ˜ํ•™ ๊ณต์‹์ด ํ•„์š”ํ•œ๊ฐ€ ๋ณด๊ตฐโ€™ ํ•˜๋ฉฐ ์กฐ๊ธˆ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ๊ตฌ๊ธ€๋ง์„ ํ–ˆ๋‹ค.
    • ๊ทธ๋žฌ๋”๋‹ˆ ๋‚˜์˜จ ๊ฒƒ์ด ๋” ์นœ์ ˆํ•œ 14924๋ฒˆ ๋ฌธ์ œ..๐Ÿชฐ
  • 14924๋ฒˆ ๋ฌธ์ œ๋ฅผ ๋ณด๋ฉด ์–ด๋–ป๊ฒŒ ํ’€๋ฉด ๋˜๋Š”์ง€ ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ค€๋‹ค.
    1. ๋‘ ๊ธฐ์ฐจ๊ฐ€ ๋งŒ๋‚˜๋Š” ์‹œ๊ฐ„์„ ๊ตฌํ•œ๋‹ค. ์‹œ๊ฐ„ = ์ด ๊ฑฐ๋ฆฌ / (๊ธฐ์ฐจA์˜ ์†๋ ฅ + ๊ธฐ์ฐจB์˜ ์†๋ ฅ)
    2. ์ฃผ์–ด์ง„ ํŒŒ๋ฆฌ์˜ ์†๋ ฅ์„ ์ด์šฉํ•ด ํŒŒ๋ฆฌ์˜ ์ด๋™๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•œ๋‹ค. ๊ฑฐ๋ฆฌ = 1.์—์„œ ๊ตฌํ•œ ์‹œ๊ฐ„ * ํŒŒ๋ฆฌ์˜ ์†๋ ฅ
  • 14924๋ฅผ ํ’€๊ณ  ๋‚˜๋ฉด 9469๋ฒˆ๋„ ํ’€ ์ˆ˜ ์žˆ๋‹ค. ๋‘ ๊ธฐ์ฐจ์˜ ์†๋ ฅ์ด ๋‹ค๋ฅด๋ฏ€๋กœ *2ํ•˜์ง€ ์•Š๊ณ  ๋”ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ๋งŒ ์œ ์˜ํ•˜๋ฉด ๋œ๋‹ค.
    • ์ถœ๋ ฅ ์‹œ ์†Œ์ˆ˜์  6์งธ์ž๋ฆฌ๊นŒ์ง€๋งŒ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ๋ฒ•์€ String(format:_:) ์„ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค. ์ž์„ธํ•œ ๊ฒƒ์€ ์—ฌ๊ธฐ ์ฐธ์กฐ.
    • ๊ทผ๋ฐ ๋‹ค๋ฅธ ๋ถ„ ํ’€์ด๋ฅผ ๋ณด๋‹ˆ ์†Œ์ˆ˜์  ๋Š์ง€ ์•Š๊ณ  ๊ทธ๋ƒฅ ์ œ์ถœํ•ด๋„ ๋งž์•˜์Šต๋‹ˆ๋‹ค๊ฐ€ ๋œฌ๋‹ค.. ๋ญ์ง€..๐Ÿค”

14924 (ํฐ ๋…ธ์ด๋งŒ๊ณผ ํŒŒ๋ฆฌ) ํ’€์ด

let inputArr = readLine()!.split(separator: " ").map { Int($0)! }
let meetTime = inputArr[2] / (inputArr[0] * 2)
print(meetTime * inputArr[1])

9469 (ํฐ ๋…ธ์ด๋งŒ) ํ’€์ด

import Foundation
let count = Int(readLine()!)!
(1...count).forEach { _ in
    let inputArr = readLine()!.split(separator: " ").map { Double($0)! }
    let meetTime = inputArr[1] / (inputArr[2] + inputArr[3])
    let flyMove = inputArr[4] * meetTime
    print("\(String(format: "%.0f", inputArr[0])) \(String(format: "%.6f", flyMove))")

}

์•„๋ž˜์™€ ๊ฐ™์ด ์ œ์ถœํ•ด๋„ ๋งž์•˜๋‹ค๊ณ  ๋œจ๊ธด ํ•œ๋‹ค.

let count = Int(readLine()!)!
(1...count).forEach { _ in
    let inputArr = readLine()!.split(separator: " ").map { Double($0)! }
    let meetTime = inputArr[1] / (inputArr[2] + inputArr[3])
    let flyMove = inputArr[4] * meetTime
    print("\(Int(inputArr[0])) \(flyMove)")
}