-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (54 loc) · 1.37 KB
/
main.cpp
File metadata and controls
65 lines (54 loc) · 1.37 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
#include <iostream>
#include <fstream>
using namespace std;
void multiplyMatricesModulo3(int** a, int** b, int** result, int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
result[i][j] = 0;
for (int k = 0; k < n; ++k) {
result[i][j] += a[i][k] * b[k][j];
result[i][j] %= 3; // ȡģ3
}
}
}
}
int main() {
ifstream infile("in.txt");
int n;
infile >> n;
int** a = new int* [n];
int** b = new int* [n];
int** result = new int* [n];
for (int i = 0; i < n; ++i) {
a[i] = new int[n];
b[i] = new int[n];
result[i] = new int[n];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
infile >> a[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
infile >> b[i][j];
}
}
multiplyMatricesModulo3(a, b, result, n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << result[i][j] << " ";
}
cout << endl;
}
for (int i = 0; i < n; ++i) {
delete[] a[i];
delete[] b[i];
delete[] result[i];
}
delete[] a;
delete[] b;
delete[] result;
infile.close();
return 0;
}