AcWing 1302. 矩阵 A × B
原题链接
简单
作者:
CoderXx
,
2020-09-14 09:52:53
,
所有人可见
,
阅读 493
java代码
import java.util.Scanner;
public class Main {
static int N = 1000;
static int[][] A = new int[N][N];
static int[][] B = new int[N][N];
static int[][] C = new int[N][N];
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
A[i][j] = in.nextInt();
int p = in.nextInt();
for (int i = 1; i <= m; i++)
for (int j = 1; j <= p; j++)
B[i][j] = in.nextInt();
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= p; j++)
for (int k = 1; k <= m; k++) {
C[i][j] += (A[i][k] * B[k][j]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= p; j++) {
System.out.print(C[i][j] + " ");
}
System.out.println();
}
in.close();
}
}