티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let input = Int(readLine()!)!
 
var count = 0
var temp: Int = input
var tempToString = String(temp)
repeat{
    if(temp < 10){
        tempToString = "0"+tempToString
    }
    let sum = Int(tempToString[tempToString.startIndex].description)! + Int(tempToString[tempToString.index(tempToString.startIndex, offsetBy: 1)].description)!
    let sumToString = String(sum)
    let newNumber: Int
    if(sum < 10){
        newNumber = Int(tempToString[tempToString.index(tempToString.startIndex, offsetBy: 1)].description + sumToString[sumToString.index(sumToString.startIndex, offsetBy: 0)].description)!
    }
    else{
        newNumber = Int(tempToString[tempToString.index(tempToString.startIndex, offsetBy: 1)].description + sumToString[sumToString.index(sumToString.startIndex, offsetBy: 1)].description)!
    }
    temp = newNumber
    tempToString = String(newNumber)
    count += 1
while(temp != input)
print(count)
cs


'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글

1193번 '분수찾기'  (0) 2018.02.22
1152번 '단어의 개수'  (0) 2018.02.22
1065번 '한수'  (0) 2018.02.22
1008번 'A / B'  (0) 2018.02.22
1001번 'A - B'  (0) 2018.02.22
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함