음양 더하기
https://programmers.co.kr/learn/courses/30/lessons/76501
코딩테스트 연습 - 음양 더하기
어떤 정수들이 있습니다. 이 정수들의 절댓값을 차례대로 담은 정수 배열 absolutes와 이 정수들의 부호를 차례대로 담은 불리언 배열 signs가 매개변수로 주어집니다. 실제 정수들의 합을 구하여 re
programmers.co.kr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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] == true) | |
answer += absolutes[i]; | |
else | |
answer -= absolutes[i]; | |
} | |
return answer; | |
} |
반응형
'자료구조 와 알고리즘 > 프로그래머스' 카테고리의 다른 글
내적 (0) | 2022.05.08 |
---|---|
K번째수 (0) | 2022.05.08 |
두 개 뽑아서 더하기 (0) | 2022.05.08 |
이상한 문자 만들기 (0) | 2022.05.08 |
자릿수 더하기 (0) | 2022.05.08 |