Study Record

[프로그래머스] Level1 - 음양 더하기 / 내적 본문

알고리즘

[프로그래머스] Level1 - 음양 더하기 / 내적

초코초코초코 2021. 12. 3. 10:38
728x90

음양 더하기

#include <string>
#include <vector>

using namespace std;

int solution(vector<int> absolutes, vector<bool> signs) {
    int answer = 0;
    for(int i=0; i<absolutes.size(); i++){
        if(signs[i]) answer += absolutes[i];
        else answer -= absolutes[i];
    }
    return answer;
}

내적

#include <string>
#include <vector>

using namespace std;

int solution(vector<int> a, vector<int> b) {
    int answer = 0;
    for(int i=0; i<a.size(); i++){
        answer += a[i] * b[i];
    }
    return answer;
}
728x90