새소식

인기 검색어

프로그래머스/Lv.1

[Swift] 숫자 문자열과 영단어

  • -
import Foundation

func solution(_ s:String) -> Int {

    let answer = s.replacingOccurrences(of: "zero", with: "0")
            .replacingOccurrences(of: "one", with: "1")
            .replacingOccurrences(of: "two", with: "2")
            .replacingOccurrences(of: "three", with: "3")
            .replacingOccurrences(of: "four", with: "4")
            .replacingOccurrences(of: "five", with: "5")
            .replacingOccurrences(of: "six", with: "6")
            .replacingOccurrences(of: "seven", with: "7")
            .replacingOccurrences(of: "eight", with: "8")
            .replacingOccurrences(of: "nine", with: "9")

    return Int(answer)!
}

 

'프로그래머스 > Lv.1' 카테고리의 다른 글

[Swift] 시저 암호  (0) 2023.02.15
[Swift] 숫자 짝궁  (0) 2023.02.15
[Swift] 수박수박수박수박수박수?  (0) 2023.02.14
[Swift] 소수 찾기  (0) 2023.02.14
[Swift] 소수 만들기  (0) 2023.02.14
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.