Created
April 4, 2017 18:30
-
-
Save JackieQi/3fa21205185422f75fd1efced86c391b to your computer and use it in GitHub Desktop.
HackerRank Stdin for Swift
This file contains hidden or 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
func readLineString() -> [String] { | |
return readLine()!.characters.split(separator: " ").map{ String($0) } | |
} | |
func readLineInt() -> [Int] { | |
return readLine()!.characters.split(separator: " ").map{ Int(String($0))! } | |
} | |
func readData() -> Data { | |
return FileHandle.standardInput.availableData | |
} | |
func readString() -> String { | |
return String(data: readData(), encoding: String.Encoding.utf8)!.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) | |
} | |
func readInt() -> Int { | |
return Int(readString())! | |
} | |
func readArrayOfStrings() -> Array<String> { | |
return readString().components(separatedBy: CharacterSet.whitespacesAndNewlines) | |
} | |
func readArrayOfInts() -> Array<Int> { | |
return readArrayOfStrings().map { | |
(str: String) -> Int in | |
return Int(str)! | |
} | |
} | |
func readArrayOfDoubles() -> Array<Double> { | |
return readArrayOfStrings().map { | |
(str: String) -> Double in | |
return Double(str)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment