MUKER_DEV with iOS
[swift] 백준 14681번 - 사분면 고르기 본문
14681번: 사분면 고르기
점 (x, y)의 사분면 번호(1, 2, 3, 4 중 하나)를 출력한다.
www.acmicpc.net
![](https://blog.kakaocdn.net/dn/bOfsHF/btrVTm1ccV9/AylSbRpaeKKkxRnGzV53yK/img.png)
처음 내가 푼 코드
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
'🤖 알고리즘 > BAEKJOON' 카테고리의 다른 글
[swift] 백준 2525번 - 오븐 시계 (0) | 2022.08.22 |
---|---|
[swift] 백준 2884번 - 알람 시계 (0) | 2022.08.22 |
[swift] 백준 2753 - 윤년 (0) | 2022.08.22 |
[swift] 백준 1330번 - 두 수 비교하기 (0) | 2022.08.21 |
[swift] 백준 25083 - 새싹 (0) | 2022.08.21 |