Skip to content

Instantly share code, notes, and snippets.

@ryosism
Last active June 25, 2018 09:05
Show Gist options
  • Save ryosism/ba6bd943d3be404a0f8f1294273e0324 to your computer and use it in GitHub Desktop.
Save ryosism/ba6bd943d3be404a0f8f1294273e0324 to your computer and use it in GitHub Desktop.
swiftの標準入力(競技用)
import Cocoa
// 標準入力で入力した行全体を取得、スペース区切りにして配列で返す
// String型の入力
func stdinStr(array:String?)->[String]{
let str: String = array!
let array = str.components(separatedBy:" ")//ここの" "を変更すると区切るワードを変えられる
return array
}
// こっちは整数に対応
// Int型の入力
func stdinNum(array:String?)->[Int]{
let str: String = array!
let array = str.components(separatedBy:" ")//ここの" "を変更すると区切るワードを変えられる
let intarray = array.map{Int($0)!}
return intarray
}
print("Please input any word")
print(stdinStr(array:readLine()))
print("Please input any number")
print(stdinNum(array:readLine()))
@ryosism
Copy link
Author

ryosism commented Nov 20, 2016

競技プログラミング用に是非!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment