본문 바로가기
코테/백준

[백준] 1011 Fly me to the Alpha Centauri 스위프트

by 리드맥 2022. 1. 5.

코드:

let input1 = Int(readLine()!)!
var k = 0
for i in 1...input1 {
    let input2 = readLine()!.split(separator: " ").map{ Int($0)!}
    var dis = input2[1] - input2[0]
    var sqrt = sqrt(Double(dis))
    var count = 0
    if Int(sqrt) < Int(ceil(sqrt)) {
        count = Int(sqrt * 2) //제곱근이 정수로 안나눠 떨어질때 6의 제곱근 * 2 = 4.8, 7의 제곱근 * 2 = 5.2
    }else {
        count = Int(sqrt * 2 ) - 1 //제곱근이 정수일때
    }
    print(count)
}

 
결과:

댓글