ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฌธ์ œ ํŒŒ์•…

  • 1๊ฐœ์˜ ์ง์„  ์ขŒํ‘œ ์œ„์— ๊ณ ์–‘์ด 2๋งˆ๋ฆฌ, ์ฅ 1๋งˆ๋ฆฌ๊ฐ€ ์œ„์น˜
  • Cat A, Cat B ์ค‘ Mouse์™€ ๋” ๊ฐ€๊นŒ์šด ์œ„์น˜์— ์žˆ๋Š” ๊ณ ์–‘์ด๋ฅผ Print ํ•˜์ž

๊ธฐํƒ€ ์กฐ๊ฑด

  • Cat A, Cat B ์™€ Mouse์˜ ๊ฑฐ๋ฆฌ๊ฐ€ ๋ชจ๋‘ ๋™์ผํ•  ๊ฒฝ์šฐ Mouse๋ฅผ Print ํ•˜์ž

ํ’€์ด- Kotlin

    fun catAndMouse(x: Int, y: Int, z: Int): String {
        val a = Math.abs(x - z)
        val b = Math.abs(y - z)

        return if (a < b) {
            "Cat A"
        } else if (a > b) {
            "Cat B"
        } else {
            "Mouse"
        }
    }

๋†“์ณค๋˜ ๋ถ€๋ถ„

์ฒ˜์Œ์— ๊ธ‰ํ•˜๊ฒŒ ๋…ผ๋ฆฌ๋งŒ ์„ธ์›Œ๋‘” ์ฑ„๋กœ ์ง„ํ–‰ํ–ˆ์„ ๋•Œ Fail์ด ๋‚˜์™€ ์‹ค๋งํ–ˆ๋‹ค.

๋‹ค์‹œ ์ฐฌ์ฐฌํ•˜๊ฒŒ ์‚ดํŽด๋ณด๋‹ˆ ๊ฐ ๊ณ ์–‘์ด๋“ค๊ณผ ์ฅ์˜ ๊ฑฐ๋ฆฌ๋Š” ์ ˆ๋Œ€๊ฐ’์œผ๋กœ ๋น„๊ตํ•ด์•ผ ํ•˜๋ฏ€๋กœ ์ ˆ๋Œ€๊ฐ’ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์•˜๋˜ ๊ฒƒ์ด๋‹ค!

์ฝ”ํ…Œ ์ค€๋น„ ์ดˆ์งœ๋กœ์„œ... ์ด๋Ÿฐ ์‚ฌ์†Œํ•˜์ง€๋งŒ ์ค‘์š”ํ•œ ์กฐ๊ฑด์€ ์•ž์œผ๋กœ ํ•œ ๋ฒˆ์— ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€?

 

 

https://www.hackerrank.com/challenges/cats-and-a-mouse/problem?h_r=internal-search 

 

Cats and a Mouse | HackerRank

Which cat will catch the mouse first?

www.hackerrank.com