Created
April 2, 2019 05:09
-
-
Save junyng/0a2b6edf4a4d2e16fc6107659f33fb08 to your computer and use it in GitHub Desktop.
Revisions
-
junyng created this gist
Apr 2, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ // // main.swift // PairProgramming // // Created by Blu X Bean on 2019. 4. 2.. // Copyright © 2019년 Blu Bean. All rights reserved. // import Foundation //print("\(120)cm to \(120 * 0.01)m") //print("\(1.86)m to \(Int(1.86 * 100))cm") func convert(value: String) { let number: Double = 100 var units = value.split(separator: " ") if units.count == 1 { if value.contains("cm") { if let convertedValue = Double(value.replacingOccurrences(of: "cm", with: "", options: .literal, range: nil)) { print("\(convertedValue / number)m") } } else if value.contains("m"){ if let convertedValue = Double(value.replacingOccurrences(of: "m", with: "", options: .literal, range: nil)) { print("\(Int(convertedValue * number))cm") } } else if value.contains("inch"){ if let convertedValue = Double(value.replacingOccurrences(of: "inch", with: "", options: .literal, range: nil)) { print("\(convertedValue * 2.54)cm") } } } else if units.count == 2 { switch units[1] { case "cm" : break case "inch" : break case "m" : break default: break } } } //let input = readLine() //convert(value: input ?? "") var s = "8inch" convert(value: s)