Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <cstddef>
- #include <iostream>
- using Matrix = std::vector<std::vector<long long>>;
- Matrix Multiply(const Matrix& A, const Matrix& B) {
- size_t n = A.size();
- size_t m = B[0].size();
- size_t q = A[0].size();
- Matrix C(n, std::vector<long long>(m, 0));
- for (size_t i = 0; i < n; ++i) {
- for (size_t j = 0; j < m; ++j) {
- for (size_t k = 0; k < q; ++k) {
- C[i][j] += A[i][k] * B[k][j];
- }
- }
- }
- return C;
- }
- void Print(const Matrix& C) {
- for (const auto& line: C) {
- for (const auto& x: line) {
- std::cout << x << ' ';
- }
- std::cout << std::endl;
- }
- }
- int main() {
- Matrix A = {
- {1 , 0 ,-1, 0},
- {0, 1, -4, -4},
- {1 ,2 ,-9 ,-8},
- {1 ,-12, 47, 48},
- };
- Matrix B = {
- {4 ,-1,-2 ,-1},
- {3 , 1 ,-1 ,-1},
- {-2 , 2 ,2 ,1},
- {-2 , 0 , 1 ,1},
- };
- Print(Multiply(A, B));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement