Diana의 iOS 개발일기

[백준 swift] 기본수학 1 - 1712번, 2292번, 2869번, 10250번 본문

알고리즘/백준

[백준 swift] 기본수학 1 - 1712번, 2292번, 2869번, 10250번

Diana_iOS 2021. 4. 9. 15:37

1712번 - 손익 분기점

import Foundation

let num = readLine()!.components(separatedBy: " ").map{Int($0)!}

if(num[1]>=num[2]){
    print(-1)
}else{
    print(num[0]/(num[2] - num[1])+1)
}

2292번 - 벌집

import Foundation

var num = Int(readLine()!)!
var plus = 0
var result = true

while(result){
    let calculate = 3*plus*(plus+1)+1
    if(num <= calculate){
        print(plus+1)
        result = false
    }
    plus += 1
}

2869번 - 달팽이는 올라가고 싶다

import Foundation

let num = readLine()!.components(separatedBy: " ").map{Double($0)!}
let up = num[2] - num[1]
let down = num[0] - num[1]
let calculate = up / down

var result = Int(ceil(calculate))
print(result)

10250번 - ACM호텔

import Foundation

let num = Int(readLine()!)!

for _ in 1...num{
    let testCase = readLine()!.components(separatedBy: " ").map{Double($0)!}
    let share = ceil(testCase[2] / testCase[0])
    var remainder = Int(testCase[2]) % Int(testCase[0])
    if remainder == 0 {
        remainder = Int(testCase[0])
    }
    let result = remainder * 100 + Int(share)
    print(result)
}