Python to Swift
while 문
10952_A+B - 5
while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break
else:
print(a+b)
import Foundation
while true {
let inputLine = readLine()!.components(separatedBy: " ")
let a = Int(inputLine[0])!
let b = Int(inputLine[1])!
if a == 0 && b == 0 {
break
} else {
print(a + b)
}
}
10951_A+B - 4
while True:
try:
a, b = map(int, input().split())
print(a + b)
except:
break
import Foundation
while let inputLine = readLine() {
let inputLineArray = inputLine.components(separatedBy: " ")
let a = Int(inputLineArray[0])!
let b = Int(inputLineArray[1])!
print(a+b)
}
1110_더하기 사이클
n = int(input())
def cycle(n):
if n >= 10:
first_num = n // 10
second_num = n % 10
else:
first_num = 0
second_num = n
sum_num_second = (first_num + second_num) % 10
new_num = second_num * 10 + sum_num_second
return new_num
count = 1
next_level = cycle(n)
while n != next_level:
count += 1
next_level = cycle(next_level)
print(count)
let inputLine = Int(readLine()!)!
func cycle(_ num: Int) -> Int {
let secondNumber = num % 10
var sumNumber: Int
if num < 10 {
sumNumber = num
} else {
sumNumber = (Int(num / 10) + (num % 10)) % 10
}
return (secondNumber * 10) + sumNumber
}
var count = 1
var temp = cycle(inputLine)
while inputLine != temp {
temp = cycle(temp)
count += 1
}
print(count)