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

[๋ฐฑ์ค€ 25024] ์‹œ๊ฐ„๊ณผ ๋‚ ์งœ (Swift) ๋ณธ๋ฌธ

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

[๋ฐฑ์ค€ 25024] ์‹œ๊ฐ„๊ณผ ๋‚ ์งœ (Swift)

๋น„๋น„ bibi 2022. 9. 17. 10:39

25024๋ฒˆ: ์‹œ๊ฐ„๊ณผ ๋‚ ์งœ

  • ์‹œ๊ฐ„ : 0-23, ๋ถ„ : 0-59
  • ์›” : 1-12
    • ์ผ : ์›”๋ณ„๋กœ ๋‹ค๋ฅด๊ฒŒ ์ ์šฉ

์ƒˆ์‚ผ ๋Š๋ผ์ง€๋งŒ ์Šค์œ„ํ”„ํŠธ์—์„œ Range์™€ switch ๋‹ค์ค‘ case ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ด์„œ ์ฐธ ํŽธํ•œ ๊ฒƒ ๊ฐ™๋‹ค.

ํ’€์ด

let inputCount = Int(readLine()!)!
(1...inputCount).forEach { _ in
    let inputArr = readLine()!.split(separator: " ").map { Int($0)! }
    var isTime = false
    var isDate = false
    if (0...23).contains(inputArr[0])
        && (0...59).contains(inputArr[1]) {
        isTime = true
    }
    if (1...12).contains(inputArr[0]) {
        switch inputArr[0] {
        case 1, 3, 5, 7, 8, 10, 12:
            if (1...31).contains(inputArr[1]) {
                isDate = true
            }
        case 4, 6, 9, 11:
            if (1...30).contains(inputArr[1]) {
                isDate = true
            }
        case 2:
            if (1...29).contains(inputArr[1]) {
                isDate = true
            }
        default:
            break
        }
    }
    print("\(isTime ? "Yes" : "No") \(isDate ? "Yes" : "No")")
}