| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- C++
- 코딩테스트
- ProblemSolving
- 파이썬
- 3D PRINTING
- 프로그래머스
- 2022
- First Unique Character in a String
- 문제해결
- Code Jam
- GitLab
- leetcode
- hackerrank
- ProblemSoving
- MySQL
- Algorithm
- K8S
- Kubernetes
- LEVEL 2
- 리트코드
- swift
- 해커랭크
- Python
- Qualification Round
- 알고리즘
- Count Monobit Integers
- Code Jam 2022
- 하늘과 바람과 별과 시
- 하늘과 바람과 별과 詩
Archives
- Today
- Total
공대생의 비망록
[프로그래머스][Lv. 1] 숫자 문자열과 영단어 Swift 풀이 본문
https://programmers.co.kr/learn/courses/30/lessons/81301
코딩테스트 연습 - 숫자 문자열과 영단어
네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자
programmers.co.kr
풀이는 추후에 차차 올리도록 하겠습니다...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import Foundation
func solution(\_ s:String) -> Int {
let dict: \[String:String\] = \["zero":"0", "one":"1", "two":"2", "three":"3", "four":"4", "five":"5", "six":"6", "seven":"7", "eight":"8", "nine":"9"\]
var ans: String = "", tmp: String = ""
for ch in s {
if ch.isNumber { // ch.isWholNumber
if !tmp.isEmpty {
ans.append(dict\[tmp\]!)
tmp.removeAll()
}
ans.append(ch)
} else {
if let temp = dict\[tmp\] {
ans.append(temp)
tmp.removeAll()
}
tmp.append(ch)
}
}
if !tmp.isEmpty {
ans.append(dict\[tmp\]!)
tmp.removeAll()
}
return Int(ans) ?? 0
}
|
cs |
'Programming Language > Swift' 카테고리의 다른 글
| [프로그래머스][Lv. 1] 크레인 인형뽑기 게임 Swift 풀이 (0) | 2022.03.14 |
|---|---|
| [프로그래머스][Lv. 1] 키패드 누르기 Swift 풀이 (0) | 2022.03.14 |
| [프로그래머스][Lv. 1] 신규 아이디 추천 Swift 풀이 (0) | 2022.03.14 |
| [프로그래머스][Lv. 1] 로또의 최고 순위와 최저 순위 Swift 풀이 (0) | 2022.03.14 |
| [프로그래머스][Lv. 1] 신고 결과 받기 Swift 풀이 (0) | 2022.03.14 |
Comments
