문제 링크입니다 https://programmers.co.kr/learn/courses/30/lessons/12950
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
두 개의 행렬을 입력받아, 행렬 덧셈의 결과를 반환하는 함수를 작성하는 문제였습니다. 행렬은 벡터 안의 벡터가 있는 2차원 배열 형태이므로 각 행마다 벡터 하나를 만들어 해당 행의 모든 원소를 더한 값을 넣고, 그 벡터를 정답 벡터에 다시 넣는 형태로 문제를 해결했습니다.
[소스코드]
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; | |
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) { | |
vector<vector<int>> answer; | |
for(int i = 0; i < arr1.size(); i++){ | |
vector <int> v; | |
for(int j = 0; j < arr1[i].size(); j++){ | |
v.push_back(arr1[i][j] + arr2[i][j]); | |
} | |
answer.push_back(v); | |
} | |
return answer; | |
} |

'알고리즘 > Programmers' 카테고리의 다른 글
프로그래머스 LEVEL 1 : 최대공약수와 최소공배수 (0) | 2020.03.15 |
---|---|
프로그래머스 LEVEL 1 : 하샤드 수 (0) | 2020.03.15 |
프로그래머스 LEVEL 1 : 예산 (0) | 2020.03.15 |
프로그래머스 LEVEL 1 : 평균 구하기 (0) | 2020.03.09 |
프로그래머스 LEVEL 1 : 핸드폰 번호 가리기 (0) | 2020.03.09 |