Algorithm/Baekjoon Online Judge

11721번 '열 개씩 끊어 출력하기'

할루루 2018. 2. 23. 10:01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let input = readLine()!
var offset: Int = 0
var startIndex = input.startIndex
if(input.count < 10){
    print(input)
}
else{
    offset = 10
    var endIndex = input.index(startIndex, offsetBy: offset)
    while(offset == 10){
        print(input[startIndex..<endIndex])
        startIndex = endIndex
        if(input[endIndex..<input.endIndex].count < 10){
            offset = input.count - endIndex.encodedOffset
        }
        else{
            offset = 10
        }
        endIndex = input.index(startIndex, offsetBy: offset)
    }
    if(input[startIndex..<endIndex].count != 10 && input[startIndex..<endIndex].count != 0){
        print(input[startIndex..<endIndex])
    }
}
cs