let a = Character("a").asciiValue!
let inputArray = readLine()!.map { $0.asciiValue! - a }
var check = Array(repeating: -1, count: 26)
(0..<26).forEach { i in
let askii = UInt8(i)
if inputArray.contains(askii) {
check[i] = inputArray.firstIndex(of: askii)!
}
}
check.forEach { num in
print(num, terminator: " ")
}
let a = Character("a").asciiValue!
let inputArray = readLine()!.map { $0.asciiValue! - a }
(0..<26).forEach { i in
let askii = UInt8(i)
if inputArray.contains(askii) {
print(inputArray.firstIndex(of: askii)!, terminator: " ")
} else {
print(-1, terminator: " ")
}
}
→ check 없이 바로바로 print하면 더 코드를 짧게 쓸 수 있습니다.