반응형
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 |
Tags
- 후행 클로저
- weak
- for-in
- uikit
- UIButton
- property wrapper
- 연산 프로퍼티
- IBOutlet
- viewcontroller
- tableViewCell
- IBOutletCollection
- CoreLocation
- OperationQueue
- TableView
- Understanding Swift Performance
- Choosing Between Structures and Classes
- userdefaults
- 원격 푸시
- entrypoint
- 트레일링 클로저
- ios
- WWDC16
- 진입점
- AppTransportSecurity
- DispatchQueue
- 동시성프로그래밍
- RunLoop
- SWiFT
- Remot Push
- firebase
Archives
- Today
- Total
iOS 공부하는 감자
백준 1931 본문
반응형
문제설명
https://www.acmicpc.net/problem/1931
1931번: 회의실 배정
(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.
www.acmicpc.net
풀이
let input: Int = Int(readLine()!)!
var inputArray: [[Int]] = []
var count: Int = 0
for _ in 1...input {
inputArray.append(readLine()!.split(separator: " ").map({Int($0)!}))
}
inputArray.sort(by: {
if $0[1] == $1[1] {
return $0[0] < $1[0]
}else {
return $0[1] < $1[1]
}
})
var current = 0
for conference in inputArray {
if conference[0] >= current {
current = conference[1]
count += 1
}
}
print(count)
정렬기준 :
회의가 끝나는 시간을 기준으로 정렬하고, 끝나는 시간이 같으면 회의 시작시간을 기준으로 정렬한다.
현재시간을 0으로 잡는다.
for문으로 배열을 순환하면서 회의 시작시간이 현재시간보다 같거나 큰 경우
현재시간을 조건에 맞는 회의의 끝나는 시간으로 업데이트하고, count를 1 증가시킨다.
for문이 종료되면 count를 print
반응형