Last active
February 22, 2017 15:04
-
-
Save AnthonyBY/64c00c5e7e3b782e4a39d2d04f0c5601 to your computer and use it in GitHub Desktop.
snippets for HackerRank on 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
//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