Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 타임라인 포맷팅
- custom navigation bar
- custombottomsheet
- swift custom ui
- swift dashed line
- swift navigationcontroller
- SWIFT
- reactorkit
- swift 백준
- rxdatasources
- 버튼 피드백
- DP
- button configuration
- traits
- domain data
- custom ui
- claen architecture
- uikit toast
- swift bottomsheet
- swift 점선
- identifiable
- task cancellation
- BFS
- task cancel
- Tuist
- RxSwift
- coordinator
- UIKit
- swift concurrency
- scene delegate
Archives
- Today
- Total
김경록의 앱 개발 여정
[Swift 백준] 18870 좌표 압축 본문
풀이 아이디어
좌표압축 문제입니다.
처음 풀어 보는 유형이지만, 간략히 요약해 보면 결국 가장 작은 값을 0으로 잡고
1씩 증가시키며 크기만 나타낼 수 있도록 하는 문제입니다.
풀이
let n = Int(readLine()!)!
let input = readLine()!.split(separator: " ").map { Int($0)! }
let sortedSet = Array(Set(input)).sorted()
var dic = [Int: Int]()
for i in 0..<sortedSet.count {
let value = sortedSet[i]
dic[value] = i
}
let result = input.map { dic[$0]! }
print(result.map { String($0) }.joined(separator: " "))
'Algorithm' 카테고리의 다른 글
[Swift 백준] 2559 수열 (0) | 2025.01.22 |
---|---|
[Swift 백준] 14465 소가 길을 건너간 이유 5 (0) | 2025.01.21 |
[Swift 백준] 17266 어두운 굴다리 (0) | 2025.01.16 |
[Swift 백준] 2512 예산 (0) | 2025.01.15 |
[Swift 백준] 나무 자르기 (0) | 2025.01.14 |