●문제

●입출력

문제해석
arr1과 arr2의 행렬을 곱한 결과를 return
푼방법
3중for문으로 answer을 행과 열로 초기화하여 풀었음
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2)
{
//arr1[2,3,2] * arr2-1열[5,2,3] = (2*5) + (3*2) + (2*3) = 10+6+6 = 22
//arr1[2,3,2] * arr2-2열[4,4,1] = (2*4) + (3*4) + (2*1) = 8+12+2 = 22
//arr1[2,3,2] * arr2-3열[3,1,1] = (2*3) + (3*1) + (2*1) = 6+3+2 = 11
//return vector<vector<int>arr2 = [[22, 22, 11], ...]
//즉 arr1의 행 * arr2의 열 을 다 더한값
vector<vector<int>> answer(arr1.size(), vector<int>(arr2[0].size(), 0));
for (int row = 0; row < answer.size(); row++)
{
for (int col = 0; col < answer[0].size(); col++)
{
for (int i = 0; i < arr1[0].size(); i++)
{
answer[row][col] += arr1[row][i] * arr2[i][col];
}
}
}
return answer;
}
레벨 : 2
점수 : 1
'C++ 프로그래머스 > 기타 문제' 카테고리의 다른 글
| 프로그래머스(C++) - 방문 길이 (0) | 2025.10.24 |
|---|---|
| 프로그래머스(C++) - 롤케이크 자르기 (0) | 2025.10.20 |
| 프로그래머스(C++) - 예상 대진표 (0) | 2025.10.12 |
| 프로그래머스(C++) - 영어 끝말잇기 (0) | 2025.10.12 |
| 프로그래머스(C++) - 귤 고르기 (0) | 2025.10.10 |
