Created
March 25, 2017 18:02
-
-
Save matteodanelli/352176b8fa5d55711e2dca605658df0f to your computer and use it in GitHub Desktop.
Google Code Jam stdin reader - Swift version
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
import Foundation | |
func readInput() { | |
let numberOfCases = Int(readLine() ?? "0")! | |
for _case in 0..<numberOfCases { | |
guard let currentLine = readLine() as String! else { | |
return | |
} | |
let lineValues = getIntegersOf(line: currentLine, separatedBy: " ") | |
let n = lineValues[0] | |
let m = lineValues[1] | |
print("Case #\(_case): \(n + m) \(n * m)"); | |
} | |
} | |
func getIntegersOf(line: String, separatedBy separator: String) -> [Int] { | |
let stringArray = line.components(separatedBy: separator) | |
// WARNING: if separator is " " and there's a space after the last number then stringArray contains empty string! | |
return stringArray.map { Int($0)! } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment