[프로그래머스] 내적 (transform. accumulate)
2021. 5. 9. 13:24ㆍ알고리즘/프로그래머스
1. 문제
코딩테스트 연습 - 내적 | 프로그래머스 (programmers.co.kr)
2. 풀이
1
2
3
4
5
6
7
8
9
10
11
|
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int solution(vector<int> a, vector<int> b) {
transform(a.begin(), a.end(), b.begin(), a.begin(), multiplies<int>());
return accumulate(a.begin(), a.end(), 0);
}
|
cs |
accumulate : 주어진 배열을 합쳐준다. (numeric)
transform: 두개의 배열에 특정한 연산을 4번째 인수에 output : algorithm
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] [C++] 단속 카메라 (set, greedy) (0) | 2021.04.06 |
---|---|
[프로그래머스] [C++] 섬 연결하기 (prim) (0) | 2021.04.04 |
[프로그래머스] [C++] 여행경로 (dfs) (0) | 2021.04.03 |
[프로그래머스] [C++] 프린터 (queue) (0) | 2021.04.01 |
[프로그래머스] [C++] 베스트앨범 (map) (0) | 2021.03.31 |