[Python To Swift] 백준 단계별로 풀어보기-if문

Cobugi·2021년 8월 13일
0

백준

목록 보기
3/21
post-thumbnail

Python to Swift

if 문


1330_두 수 비교하기

  • Python
a, b = map(int, input().split())

if a < b:
    print("<")
elif a > b:
    print(">")
else:
    print("==")
  • Swift
import Foundation

let inputLine = readLine()!
let inputLineArray = inputLine.components(separatedBy: " ")
let a = Int(inputLineArray[0])!
let b = Int(inputLineArray[1])!

if a < b {
    print("<")
} else if a > b {
    print(">")
} else {
    print("==")
}

9498_시험 성적

  • Python
a = int(input())

if a <= 100 and a>= 90:
    print("A")
elif a <= 89 and a>= 80:
    print("B")
elif a <= 79 and a>= 70:
    print("C")
elif a <= 69 and a>= 60:
    print("D")
else:
    print("F")
  • Swift
import Foundation

if let tempScore = readLine() {
    let score = Int(tempScore)!
    if score <= 100 && score >= 90 {
        print("A")
    } else if score <= 89 && score >= 80 {
        print("B")
    } else if score <= 79 && score >= 70 {
        print("C")
    } else if score <= 69 && score >= 60 {
        print("D")
    } else {
        print("F")
    }
}

2753_윤년

  • Python
a = int(input())

if a % 4 == 0 and a % 100 != 0:
    print("1")
elif a % 400 == 0:
    print("1")
else:
    print("0")
  • Swift
import Foundation

if let tempYear = readLine() {
    let year = Int(tempYear)!
    if year % 4 == 0 && year % 100 != 0 {
        print("1")
    } else if year % 400 == 0 {
        print("1")
    } else {
        print("0")
    }
}

14681_사분면 고르기

  • Python
a = int(input())
b = int(input())

if a > 0 and b > 0:
    print(1)
elif a < 0 and b > 0:
    print(2)
elif a < 0 and b < 0:
    print(3)
elif a > 0 and b < 0:
    print(4)
  • Swift
import Foundation

if let tempX = readLine(), let tempY = readLine() {
    let x = Int(tempX)!
    let y = Int(tempY)!
    if x > 0 && y > 0 {
        print(1)
    } else if x < 0 && y > 0 {
        print(2)
    } else if x < 0 && y < 0 {
        print(3)
    } else if x > 0 && y < 0 {
        print(4)
    }
}

2884_알람시계

  • Python
h, m = map(int, input().split())
if h == 0 and m < 45 :
  h = 24 * 60
else:
  h *= 60

total_time = h + m

alarm_time = total_time - 45

alarm_h, alarm_m = divmod(alarm_time, 60)

print(alarm_h, alarm_m)
  • Swift
import Foundation

let inputLine = readLine()!
let inputLineArray = inputLine.components(separatedBy: " ")
let hour = Int(inputLineArray[0])!
let minute = Int(inputLineArray[1])!

var totalMinute = 60 * hour + minute

if totalMinute < 45 {
   totalMinute += 24 * 60
    let earlyAlarm = totalMinute - 45
    print(earlyAlarm / 60, earlyAlarm % 60)

} else {
    let earlyAlarm = totalMinute - 45
    print(earlyAlarm / 60, earlyAlarm % 60)
}
profile
iOS Developer 🐢

0개의 댓글