ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Kotlin ๐Ÿฌ ๋ฐฑ์ค€ 10๋‹จ๊ณ„ :: 5073 ๋ฒˆ
    2023. 5. 28. 19:02
    ๋ฐ˜์‘ํ˜•

    ์‚ผ๊ฐํ˜•๊ณผ ์„ธ ๋ณ€

    ๋ฌธ์ œ   |

      ์‚ผ๊ฐํ˜•์˜ ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๋ณ€์˜ ๊ธธ์ด์— ๋”ฐ๋ผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •์˜ํ•œ๋‹ค.

    • Equilateral :  ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ๋ชจ๋‘ ๊ฐ™์€ ๊ฒฝ์šฐ
    • Isosceles : ๋‘ ๋ณ€์˜ ๊ธธ์ด๋งŒ ๊ฐ™์€ ๊ฒฝ์šฐ
    • Scalene : ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ๋ชจ๋‘ ๋‹ค๋ฅธ ๊ฒฝ์šฐ

     

      ๋‹จ ์ฃผ์–ด์ง„ ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ์‚ผ๊ฐํ˜•์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” "Invalid" ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 6, 3, 2๊ฐ€ ์ด ๊ฒฝ์šฐ์— ํ•ด๋‹นํ•œ๋‹ค. ๊ฐ€์žฅ ๊ธด ๋ณ€์˜ ๊ธธ์ด๋ณด๋‹ค ๋‚˜๋จธ์ง€ ๋‘ ๋ณ€์˜ ๊ธธ์ด์˜ ํ•ฉ์ด ๊ธธ์ง€ ์•Š์œผ๋ฉด ์‚ผ๊ฐํ˜•์˜ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ๋ชปํ•œ๋‹ค.

      ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ์œ„ ์ •์˜์— ๋”ฐ๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

    ์ž…๋ ฅ   |

      ๊ฐ ์ค„์—๋Š” 1,000์„ ๋„˜์ง€ ์•Š๋Š” ์–‘์˜ ์ •์ˆ˜ 3๊ฐœ๊ฐ€ ์ž…๋ ฅ๋œ๋‹ค. ๋งˆ์ง€๋ง‰ ์ค„์€ 0 0 0์ด๋ฉฐ ์ด ์ค„์€ ๊ณ„์‚ฐํ•˜์ง€ ์•Š๋Š”๋‹ค.

     

    ์ถœ๋ ฅ   |

      ๊ฐ ์ž…๋ ฅ์— ๋งž๋Š” ๊ฒฐ๊ณผ (Equilateral, Isosceles, Scalene, Invalid) ๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

     

     

    ํ’€์ด  |

      ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’๋“ค์„ ๋ฐฐ์—ด์— ๋„ฃ์–ด ๊ฐ ์กฐ๊ฑด์— ๋งž์ถ”์–ด ๋น„๊ต

     

     

    ๋‹ต์•ˆ  |

    import java.util.Scanner
    
    fun main() = with(Scanner(System.`in`)) {
        while (true) {
            val triangle : Array<Int> = arrayOf(nextInt(), nextInt(), nextInt())
            triangle.sort()
            
            if (triangle[0] == 0) {
                break
            }
            
            if (triangle[2] >= triangle[0] + triangle[1]) {
                println("Invalid")
            } else {
                when (triangle.groupBy { it }.size) {
                    1 -> println("Equilateral")
                    2 -> println("Isosceles")
                    else -> println("Scalene")
                }
            }
        }
    }
    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.