티스토리 뷰
let numOfTestCases = Int(readLine()!)!
var testArray: [Int] = []
for _ in 1...numOfTestCases{
testArray.append(Int(readLine()!)!)
}
let fibonacciSequence = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]
for i in testArray{
switch i {
case 0:
print ("1 0")
case 1:
print("0 1")
case 2:
print("1 1")
case 3...15:
print("\(fibonacciSequence[i-2])" + " " + "\(fibonacciSequence[i-1])")
case 16...40:
var newArray = fibonacciSequence
for k in 16...i{
newArray.append(newArray[k-2] + newArray[k-3])
}
print("\(newArray[i-2])" + " " + "\(newArray[i-1])")
default:
break
}
}
'Algorithm > noj.am' 카테고리의 다른 글
[Swift] 백준 10998 (0) | 2019.11.07 |
---|---|
[Swift] 백준 2947 (0) | 2019.11.07 |
[Swift] 백준 1181 (0) | 2019.11.07 |
[Swift]백준 1157 / 딕셔너리 (0) | 2019.11.07 |
[Swift] 백준 5622번 / readLine() / switch문 (0) | 2019.11.07 |