Skip to content

Instantly share code, notes, and snippets.

@junyng
Created April 2, 2019 05:09
Show Gist options
  • Select an option

  • Save junyng/0a2b6edf4a4d2e16fc6107659f33fb08 to your computer and use it in GitHub Desktop.

Select an option

Save junyng/0a2b6edf4a4d2e16fc6107659f33fb08 to your computer and use it in GitHub Desktop.

Revisions

  1. junyng created this gist Apr 2, 2019.
    48 changes: 48 additions & 0 deletions main.swift
    Original 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)