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
- ReactiveX
- Content Compression Resistance priority
- 오토레이아웃
- 버블정렬
- 선택정렬
- RxSwift요약
- 동시성프로그래밍
- GCD
- coordinator
- uikit
- Autolayout
- RxCocoa
- 알고리즘
- IOS
- Content Hugging priority
- endpoint
- swift알고리즘
- 동작과정
- mvvm
- ai expo
- 병합정렬
- swift
- 자료구조
- RX
- OperationQueue
- rxswift
- 백준
- LLM
- 삽입정렬
- Union-Find
Archives
- Today
- Total
JosephCha의 개발일지
[브루트 포스]백준/2798번/블랙잭 본문
반응형
let firstLineInput = readLine()!.split(separator: " ").map{Int(String($0))!}
let secondLineInput = readLine()!.split(separator: " ").map{Int(String($0))!}
let limit: Int = firstLineInput.last!
let length: Int = secondLineInput.count
var result: Int = 0
for i in 0..<length {
for j in i+1..<length {
for k in j+1..<length {
let sum: Int = secondLineInput[i] + secondLineInput[j] + secondLineInput[k]
if sum <= limit {
result = max(result, sum)
}
}
}
}
print(result)
설명
- 세개의 for문을 통해, 모든경우의 수의 세개의 카드의 합을 구해, result에 최대값을 갱신해 준다.
- 모든 경우의 수를 탐색하기에 브루트 포스
'알고리즘 및 자료구조' 카테고리의 다른 글
[백준] 4195번 / 친구 네트워크 (Swift) (0) | 2022.08.23 |
---|---|
[스택] 백준/1874번/스택 수열 (0) | 2022.07.27 |
백준/2920번/음계 문제 (0) | 2022.07.26 |
큐 (0) | 2022.04.20 |
스택 (0) | 2022.04.20 |
Comments