티스토리 뷰
https://programmers.co.kr/learn/courses/30/lessons/86051?language=cpp
코딩테스트 연습 - 없는 숫자 더하기
0부터 9까지의 숫자 중 일부가 들어있는 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요. 제한
programmers.co.kr
다른 분들 풀이를 봤는데
범위내의 수를 모두 더해주는 accumulate라는 함수가 있었다. (곱도가능, #include <numeric>)

(시작 iterator, 끝 iterator, 더하기 시작할 숫자)
위 사진에선 세번째 파라미터로 10을 줬기때문에 10부터 더하기 시작해서 결과는 65가 나왔다.
https://en.cppreference.com/w/cpp/algorithm/accumulate
std::accumulate - cppreference.com
(1) template< class InputIt, class T > T accumulate( InputIt first, InputIt last, T init ); (until C++20) template< class InputIt, class T > constexpr T accumulate( InputIt first, InputIt last, T init ); (since C++20) (2) template< class InputIt, class T,
en.cppreference.com
'PS' 카테고리의 다른 글
| 프로그래머스. 비밀지도 (0) | 2021.09.15 |
|---|---|
| 프로그래머스. 완주하지 못한 선수 (0) | 2021.09.15 |
| 프로그래머스. 크레인 인형 뽑기 게임 (0) | 2021.09.14 |
| 프로그래머스. 키패드 누르기 (0) | 2021.09.14 |
| 프로그래머스. 숫자 문자열과 영단어 (0) | 2021.09.14 |
- Total
- Today
- Yesterday
- db
- back tracking
- Spring
- dfs
- priority queue
- Tree
- recursion
- BFS
- binary search
- Dijkstra
- Stack
- DP
- 재귀
- MVC
- permutation
- Brute Force
- Kruskal
- CSS
- greedy
- two pointer
- graph
- Python
- Implementation
- C
- 자료구조
- Unity
- 조합
- 이분탐색
- C++
- floyd warshall
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
