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

[๋ฐฑ์ค€ 10101] ์‚ผ๊ฐํ˜• ์™ธ์šฐ๊ธฐ(Swift) ๋ณธ๋ฌธ

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

[๋ฐฑ์ค€ 10101] ์‚ผ๊ฐํ˜• ์™ธ์šฐ๊ธฐ(Swift)

๋น„๋น„ bibi 2022. 12. 14. 11:29

10101๋ฒˆ: ์‚ผ๊ฐํ˜• ์™ธ์šฐ๊ธฐ

  • ์ฃผ์–ด์ง„ ๋Œ€๋กœ ์ถœ๋ ฅ์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋˜๋Š” ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์ด๋‹ค.

ํ’€์ด1 (69100KB, 8ms)

var triangleArray = Array<Int>()
(1...3).forEach { _ in
    triangleArray.append(Int(readLine()!)!)
}
if triangleArray.reduce(0, +) == 180 {
    if triangleArray[0] == triangleArray[1] && triangleArray[1] == triangleArray[2] {
        print("Equilateral")
    } else if triangleArray[0] == triangleArray[1] || triangleArray[1] == triangleArray[2] || triangleArray[0] == triangleArray[2] {
        print("Isosceles")
    } else {
        print("Scalene")
    }
} else {
    print("Error")
}

ํ’€์ด2

๋‹ค๋ฅธ ๋ถ„๋“ค ํ’€์ด๋ฅผ ๋ณด๋‹ˆ ๊ณต๊ฐ„๋ณต์žก๋„๊ฐ€ ํ›จ์”ฌ ์ ๊ฒŒ ๋‚˜์™”๊ธธ๋ž˜ โ€˜๋‚˜๋„ ๋ฐฐ์—ด์„ ์•ˆ ์“ฐ๊ณ  ๋‹จ์ˆœํžˆ ์„ธ๋ฒˆ ์ž…๋ ฅ๋ฐ›๊ณ  ๊ณ ์ฐจํ•จ์ˆ˜๋ฅผ ์•ˆ ์“ฐ๋ฉด ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋œ ์“ฐ๋ ค๋‚˜?โ€™ํ•ด์„œ ๊ทธ๋ ‡๊ฒŒ๋„ ๋ฐ”๊ฟ”๋ดค๋Š”๋ฐ, ์ฑ„์ ํ•ด๋ด๋„ ๊ณต๊ฐ„๋ณต์žก๋„๊ฐ€ ๋™์ผํ•˜๋‹ค.

์˜›๋‚ ๊ณผ ์ฑ„์  ๊ธฐ์ค€์ด ๋‹ฌ๋ผ์ง„๊ฑธ๊นŒ..?๐Ÿค” ๊ถ๊ธˆํ•˜๋‹ค..

let x = Int(readLine()!)!
let y = Int(readLine()!)!
let z = Int(readLine()!)!
if x + y + z == 180 {
    if x == y && y == z {
        print("Equilateral")
    } else if x == y || y == z || x == z {
        print("Isosceles")
    } else {
        print("Scalene")
    }
} else {
    print("Error")
}