https://school.programmers.co.kr/learn/courses/30/lessons/12949
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
매우 오랜만에 접하는 행렬이다. 짝이 맞지 않는 케이스는 들어오지 않으니 예외처리 할 필요 없이 구현만 하면 된다.
#include <string>
#include <vector>
using namespace std;
int get_multi(vector<vector<int>> arr1, vector<vector<int>> arr2, int i, int j)
{
int res = 0;
for (int idx = 0; idx < arr1[0].size(); idx++) // 반대다 행렬의 곱이니까
res += arr1[i][idx] * arr2[idx][j];
return res;
}
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) {
vector<vector<int>> answer(arr1.size(), vector<int>(arr2[0].size()));
for (int i = 0; i < arr1.size(); i++)
for (int j = 0; j < arr2[0].size(); j++)
answer[i][j] = get_multi(arr1, arr2, i, j);
return answer;
}
/*
0,0 0,1 0,0 0,1
1,0 1,1 1,0 1,1
2,0 2,1
(0,0)*(0,0) + (0,1)*(1,0), (0,0)*(0,1) + (0,1)*(1,1)
1 4 3 2
3 2 3 4
4 1
1 * 3 + 4 * 3 , 1 * 2 + 4 * 4
3 * 3 + 2 * 3 , 3 * 2 + 2 * 4
4 * 3 + 1 * 3 , 4 * 2 + 1 * 4
*/
엄청 헷갈렸다 종이랑 펜 없이는 힘들었을 듯...
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 할인 행사 c++ (4) | 2023.06.24 |
---|---|
프로그래머스 튜플 c++ (2) | 2023.06.22 |
프로그래머스 캐시 c++ (0) | 2023.06.05 |
프로그래머스 n^2 배열 자르기 c++ (0) | 2023.06.01 |
프로그래머스 괄호 회전하기 c++ (0) | 2023.06.01 |