Diana의 iOS 개발일기

[백준 swift] while문 - 1110번 본문

알고리즘/백준

[백준 swift] while문 - 1110번

Diana_iOS 2021. 4. 1. 09:07

1110번

import Foundation

var num = Int(readLine()!)!
var stnd = num
var count : Int = 0
var x = 0
var result: Bool = true

while result {
    
    x = num
    
    let rightNum = num % 10
    let reRightNum = ((num / 10) + (num % 10)) % 10
    
    num = rightNum * 10 + reRightNum

    count += 1
    
    if stnd == num {
        print(count)
        result = false
    }
}

이후 수정

import Foundation

var num = Int(readLine()!)!
var stnd = num
var count : Int = 0

repeat {
    
    let rightNum = num % 10
    let reRightNum = ((num / 10) + (num % 10)) % 10
    
    num = rightNum * 10 + reRightNum

    count += 1
    
} while(stnd != num)

print(count)