개인적으로 문자열은 배열로 만든 뒤 다루는 게 편하다.
import Foundation
let T = Int(String(readLine()!))!
for _ in 0..<T {
let sentence = Array(readLine()!.split(separator: " ")).map{String($0)}
makeReverseSentence(sentence: sentence)
}
func makeReverseSentence(sentence: [String]) {
for word in sentence {
let wordArray = Array(word).map{String($0)}
let reversedWord = wordArray.reversed().joined()
print(reversedWord, terminator: " ")
}
}