我正在玩 HackerRank。我需要从行读取整数数组的问题之一:
A=(1,2,3)
B=(1,4,7)
我尝试过:
let line = readLine()
print(line)
但我收到此错误:
solution.swift:2:7: warning: expression implicitly coerced from 'String?' to Any
print(line)
^~~~
solution.swift:2:7: note: provide a default value to avoid this warning
print(line)
^~~~
?? <#default value#>
solution.swift:2:7: note: force-unwrap the value to avoid this warning
print(line)
^~~~
!
solution.swift:2:7: note: explicitly cast to Any with 'as Any' to silence this warning
print(line)
^~~~
as Any
你们中有人知道我应该如何读取行并获取数组吗?
非常感谢您的帮助
最佳答案
let line = readLine()!
print(line)
//To Array, should work. Wrote it real quick
let array = readLine()!.characters.split(" ").map( { String($0)! } )
关于arrays - Swift:HackerRank readLine 一个 Int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42450921/