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
- SWIFT
- custombottomsheet
- swift navigationcontroller
- swift 점선
- 버튼 피드백
- uikit toast
- rxdatasources
- BFS
- reactorkit
- coordinator
- traits
- Tuist
- task cancel
- custom navigation bar
- custom ui
- swift 백준
- swift custom ui
- DP
- swift concurrency
- task cancellation
- domain data
- scene delegate
- RxSwift
- swift bottomsheet
- button configuration
- swift dashed line
- 타임라인 포맷팅
- claen architecture
- identifiable
- UIKit
Archives
- Today
- Total
김경록의 앱 개발 여정
[Swift 백준] 7785 회사에 있는 사람 본문
https://www.acmicpc.net/problem/7785
풀이 아이디어
해시 문제입니다.
최초에 출근 set, 퇴근 set을 받고, subtracting를 통해 남은 사람을 구하여 제출하였는데 오답처리가 되었습니다.
이 경우엔 중복 입장의 경우를 처리하지 못하는 게 문제였습니다.
예를 들어, A라는 사람이 2회 출근하고 1회 퇴근했다면 회사에 남은 사람 있어야 하는데
제 최초 풀이는 해당 과정은 처리하지 못했습니다.
단순히 하나의 Set에서 inset와 remove를 해주는 걸로 수정하였습니다.
let n = Int(readLine()!)!
var set = Set<String>()
for _ in 0..<n {
let input = readLine()!.split(separator: " ").map{ String($0)}
if input[1] == "enter" {
set.insert(input[0])
} else {
set.remove(input[0])
}
}
// 순서대로 출력을해야해서 순서가 없는 set은 그대로 사용할 수 없습니다.
var resultArr = Array(set).sorted {
$0 > $1
}
resultArr.forEach {
print($0)
}
'Algorithm' 카테고리의 다른 글
[Swift 백준] 16173 점프왕 쩰리 (Small) (0) | 2025.03.05 |
---|---|
[Swift 백준] 24480 알고리즘 수업 - 깊이 우선 탐색 2 (0) | 2025.02.26 |
[Swift 백준] 5567 결혼식 (0) | 2025.02.19 |
[Swift 백준] 18352 특정 거리의 도시 찾기 (0) | 2025.02.17 |
[Swift 백준] 1389 케빈 베이컨의 6단계 법칙 (0) | 2025.02.16 |