문제 링크입니다: https://programmers.co.kr/learn/courses/30/lessons/76501
코딩테스트 연습 - 음양 더하기
어떤 정수들이 있습니다. 이 정수들의 절댓값을 차례대로 담은 정수 배열 absolutes와 이 정수들의 부호를 차례대로 담은 불리언 배열 signs가 매개변수로 주어집니다. 실제 정수들의 합을 구하여 re
programmers.co.kr
간단한 구현 문제였습니다.
This file contains hidden or 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++) | |
{ | |
answer += absolutes[i] * (signs[i] ? 1 : -1); | |
} | |
return answer; | |
} |

개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] 괄호 회전하기 (0) | 2021.10.06 |
---|---|
[Programmers] 약수의 개수와 덧셈 (0) | 2021.10.06 |
[Programmers 위클리 챌린지 9주차] 전력망을 둘로 나누기 (0) | 2021.10.06 |
[Programmers] 트리 트리오 중간값 (0) | 2021.10.03 |
[Programmers] 스타 수열 (0) | 2021.10.03 |