티스토리 뷰

Algorithm/noj.am

[Swift] 백준 1003번

SweetDev 2019. 11. 7. 18:02

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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함