행렬의 덧셈
https://programmers.co.kr/learn/courses/30/lessons/12950
코딩테스트 연습 - 행렬의 덧셈
행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요
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; | |
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) { | |
vector<vector<int>> answer(arr1.size(), vector<int>(arr1[0].size())); | |
for (int x = 0; x < arr1.size(); ++x) | |
{ | |
for (int y = 0; y < arr1[0].size(); ++y) | |
{ | |
answer[x][y] = (arr1[x][y] + arr2[x][y]); | |
} | |
} | |
return answer; | |
} |
반응형
'자료구조 와 알고리즘 > 프로그래머스' 카테고리의 다른 글
평균 구하기 (0) | 2022.05.08 |
---|---|
하샤드 수 (0) | 2022.05.08 |
핸드폰 번호 가리기 (0) | 2022.05.08 |
x만큼 간격이 있는 n개의 숫자 (0) | 2022.05.08 |
직사각형 별찍기 (0) | 2022.05.08 |