import Foundation
func diagonalDifference(arr: [[Int]]) -> Int {
}
let stdout = ProcessInfo.processInfo.environment["OUTPUT_PATH"]!
FileManager.default.createFile(atPath: stdout, contents: nil, attributes: nil)
let fileHandle = FileHandle(forWritingAtPath: stdout)!
guard let n = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!)
else { fatalError("Bad input") }
let arr: [[Int]] = AnyIterator{ readLine() }.prefix(n).map {
let arrRow: [Int] = $0.split(separator: " ").map {
if let arrItem = Int($0.trimmingCharacters(in: .whitespacesAndNewlines)) {
return arrItem
} else { fatalError("Bad input") }
}
guard arrRow.count == n else { fatalError("Bad input") }
return arrRow
}
guard arr.count == n else { fatalError("Bad input") }
let result = diagonalDifference(arr: arr)
fileHandle.write(String(result).data(using: .utf8)!)
fileHandle.write("\n".data(using: .utf8)!)
I just want to know ,is there any main function in swift like java which run first? and How should i scan a line or int in swift through console?