-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.java
49 lines (45 loc) · 1.3 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package L1_048;
import java.util.Scanner;
/**
* @author zmj
* @create 2019/5/6
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] a = new int[105][105];
int[][] b = new int[105][105];
int ra = sc.nextInt();
int ca = sc.nextInt();
for (int i = 0; i < ra; i++) {
for (int j = 0; j < ca; j++) {
a[i][j] = sc.nextInt();
}
}
int rb = sc.nextInt();
int cb = sc.nextInt();
for (int i = 0; i < rb; i++) {
for (int j = 0; j < cb; j++) {
b[i][j] = sc.nextInt();
}
}
if (ca != rb) {
System.out.println(String.format("Error: %d != %d", ca, rb));
} else {
System.out.println(ra + " " + cb);
for (int i = 0; i < ra; i++) {
for (int k = 0; k < cb; k++) {
int sum = 0;
for (int j = 0; j < ca; j++) {
sum += a[i][j] * b[j][k];
}
if (k != 0) {
System.out.print(" ");
}
System.out.print(sum);
}
System.out.println();
}
}
}
}