-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThanosReturn.cpp
100 lines (98 loc) · 2.11 KB
/
ThanosReturn.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <bits/stdc++.h>
const int MAX_N = 102;
class Matrix
{
public:
Matrix()
{
row = col = 0;
memset(mat, 0, sizeof(mat));
}
// TODO
Matrix(int r, int c);
const int &getrow()
{
return row;
}
const int &getcol()
{
return col;
}
// TODO
int *operator[](const int &x);
const int *operator[](const int &x) const
{
return mat[x];
}
// TODO
Matrix operator+(const Matrix &x) const;
// TODO: note that this function is declared with the keyword "friend"
friend Matrix operator*(const Matrix &x, const Matrix &y);
void print()
{
for (int i = 0; i < row; i++)
{
if (i == 0)
std::cout << "/";
else if (i == row - 1)
std::cout << "\\";
else
std::cout << "|";
for (int j = 0; j < col; j++)
{
std::cout << std::right << std::setw(8) << mat[i][j];
}
if (i == 0)
std::cout << " \\\n";
else if (i == row - 1)
std::cout << " /\n";
else
std::cout << " |\n";
}
}
private:
int mat[MAX_N][MAX_N];
int row, col;
};
//
//
#include <cstring>
const int MOD = 10007;
Matrix operator*(const Matrix &x, const Matrix &y)
{
Matrix res(x.row, y.col);
for (int i = 0; i < x.row; i++)
{
for (int j = 0; j < x.col; j++)
{
for (int k = 0; k < y.col; k++)
{
res[i][k] += ((x[i][j] * y[j][k]) % MOD + MOD) % MOD;
res[i][k] = (res[i][k] % MOD + MOD) % MOD;
}
}
}
return res;
}
Matrix Matrix::operator+(const Matrix &x) const
{
Matrix res(row, col);
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
res[i][j] = ((mat[i][j] + x[i][j]) % MOD + MOD) % MOD;
}
}
return res;
}
int *Matrix::operator[](const int &x)
{
return mat[x];
}
Matrix::Matrix(int r, int c)
{
row = r;
col = c;
memset(mat, 0, sizeof(mat));
}