[프로그래머스] 내적 (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