문제 설명
행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다.
2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요.
문제 유형
- 다차원 배열 순환
코드 작성
#include <vector>
using namespace std;
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
vector<vector<int>> answer;
for (int y = 0; y < arr1.size(); y++)
{
vector<int> temp;
for (int x = 0; x < arr1[y].size(); x++)
{
temp.push_back(arr1[y][x] + arr2[y][x]);
}
answer.push_back(temp);
}
return answer;
}'Algorithm > Practice' 카테고리의 다른 글
| [Algorithm] 최대공약수와 최소공배수 (0) | 2024.12.23 |
|---|---|
| [Algorithm] 직사각형 별찍기 (1) | 2024.12.22 |
| [Algorithm] 부족한 금액 계산하기 (0) | 2024.12.18 |
| [Algorithm] 문자열 내림차순으로 배치하기 (1) | 2024.12.17 |
| [Algorithm] 약수의 개수와 덧셈 (1) | 2024.12.17 |