forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbac2740.java
More file actions
88 lines (67 loc) · 1.75 KB
/
bac2740.java
File metadata and controls
88 lines (67 loc) · 1.75 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class bac2740 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int Am, An;
int Bm, Bn;
int A[][];
int B[][];
int C[][];
Am = sc.nextInt();
An = sc.nextInt();
sc.nextLine();
A = new int[Am][An];
for(int i=0; i<Am; i++)
{
for(int j=0; j<An; j++)
{
A[i][j] = sc.nextInt();
}
sc.nextLine();
}
Bm = sc.nextInt();
Bn = sc.nextInt();
sc.nextLine();
B = new int[Bm][Bn];
for(int i=0; i<Bm; i++)
{
for(int j=0; j<Bn; j++)
{
B[i][j] = sc.nextInt();
}
sc.nextLine();
}
//곱셈
// C(1,1) = A(1,1)*B(1,1) + A(1,2)*B(2,1)
// C(1,2) = A(2,1)*B(1,2) + A(2,2)*B(2,2)
// C(1,3) = A(3,1)*B(1,3) + A(3,2)*B(2,3)
// C(2,1) = A(2,1)*B(1,1) + A(2,2)*B(2,1)
// C(2,2) = A(2,1)*B(2,1) + A(2,2)*B(2,2)
// C(2,3) = A(2,1)*B(3,1) + A(2,2)*B(2,3)
C = new int[Am][Bn];
for(int i=0; i<Am; i++) {
for (int j = 0; j <Bn ; j++) {
for (int k = 0; k < An; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
//ShowArr(A,Am,An);
//ShowArr(B,Bm,Bn);
ShowArr(C,Am,Bn);
}
public static void ShowArr(int[][] Arr, int m, int n)
{
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
System.out.print(Arr[i][j] + " ");
}
System.out.println();
}
}
}