알고리즘/스위프트 알고리즘
백준 9093 - 스위프트 풀이
asong
2022. 2. 3. 22:39
let n: Int = Int(readLine()!)!
var str: String = ""
for _ in 0..<n {
let input = readLine()!
let arr = input.split(separator: " ")
for word in arr {
var wordStr = ""
for c in word {
wordStr = String(c) + wordStr
}
str += wordStr + " "
}
str += "\n"
}
print(str)
다른 사람의 깔끔한 풀이
let t = Int(readLine()!)!
for _ in 0..<t {
let words = readLine()!.split(separator: " ").map{String($0)}
var arr = [String]()
for word in words {
var temp = ""
for str in word.reversed() {
temp += String(str)
}
arr.append(temp)
}
let result = arr.joined(separator: " ")
print(result)
}