Last active
June 25, 2018 09:05
-
-
Save ryosism/ba6bd943d3be404a0f8f1294273e0324 to your computer and use it in GitHub Desktop.
swiftの標準入力(競技用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
競技プログラミング用に是非!!