丑陋又直接
#include <iostream> #include <vector> using namespace std; void calMul(vector<vector<int>> a, vector<vector<int>> b, int x, int y, int z){ vector<vector<int>> res(x, vector<int>(z, 0)); for(int i = 0; i < x; i ++){ for(int j = 0; j < z; j ++){ for(int k = 0; k < y; k ++) res[i][j] += a[i][k] * b[k][j]; } } for(int i = 0; i < x; i ++){ for(int j = 0; j < z; j ++){ cout << res[i][j] << ' '; } cout << endl; } } int main() { int x, y, z; cin >> x >> y >> z; vector<vector<int>> a(x, vector<int> (y, 0)); vector<vector<int>> b(y, vector<int> (z, 0)); for(int i = 0; i < x; i ++){ for(int j = 0; j < y; j ++){ cin >> a[i][j]; } } for(int i = 0; i < y; i ++){ for(int j = 0; j < z; j ++){ cin >> b[i][j]; } } calMul(a, b, x, y, z); return 0; } // 64 位输出请用 printf("%lld")