MUKER_DEV with iOS

[swift] 백준 14681번 - 사분면 고르기 본문

🤖 알고리즘/BAEKJOON

[swift] 백준 14681번 - 사분면 고르기

MUKER 2022. 8. 22. 00:56
 

14681번: 사분면 고르기

점 (x, y)의 사분면 번호(1, 2, 3, 4 중 하나)를 출력한다.

www.acmicpc.net


 

처음 내가 푼 코드

var input = Int(readLine()!)!
var input2 = Int(readLine()!)!

if input > 0 && input2 > 0 {
    print("1")
} else if input < 0 && input2 > 0 {
    print("2")
} else if input < 0 && input2 < 0 {
    print("3")
} else if input > 0 && input2 < 0 {
    print("4")
}

69100kb, 12ms, 261b

 

개선시켜 본 코드

- 시간이 줄어듬.

- 코드가 줄어듬.

var input = Int(readLine()!)!
var input2 = Int(readLine()!)!

if input > 0 {
    if input2 > 0 {
        print("1")
    } else {
        print("4")
    }
} else {
    if input2 > 0 {
        print("2")
    } else {
        print("3")
    }
}

69100kb, 8ms, 242b