Skip to content

Instantly share code, notes, and snippets.

@AnthonyBY
Last active February 22, 2017 15:04
Show Gist options
  • Save AnthonyBY/64c00c5e7e3b782e4a39d2d04f0c5601 to your computer and use it in GitHub Desktop.
Save AnthonyBY/64c00c5e7e3b782e4a39d2d04f0c5601 to your computer and use it in GitHub Desktop.
snippets for HackerRank on swift
//Read 2D Array of Int 5x5
var arr : [[Int]] = Array(repeating: Array(repeating: 0, count: 6), count: 6)
for i in 0...5 {
arr[i] = readLine()!.characters.split(separator: " ").map{ Int(String($0))! }
}
//Read Number
let mealCost = Double(readLine()!)!
//Read Int
let tipPercent = Int(readLine()!)!
let string = String(readLine()!)
// Read array of int with n elements with " " separated - Swift 3.0
var d = Int(readLine()!)!
var arr = readLine()!.components(separatedBy: " ").map{ Int($0)! }
//Print Array with " " separator
for i in arr {
print(i, terminator: " ")
}
//Day 8: Dictionaries and Maps - Swift
//!Read all input as one string (because Array is generation timout )
let n = Int(readLine()!)!
var string = String(n) + "\n"
while let thing = readLine() {
string += thing + "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment