-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaxtrixOperator.cpp
94 lines (91 loc) · 2.33 KB
/
MaxtrixOperator.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
#define int long long
const int MOD=1e9+7;
class matrix {
int row,col;
vector<vector<int>>arr;
public:
matrix(int n_, int m_) ;
matrix(vector<vector<int>> &a) {}
friend matrix &operator = (const matrix &);
friend matrix &operator +=(matrix&, const matrix &);
friend matrix operator + (const matrix &,const matrix &);
friend maxtrix &operator -=(matrix &, const matrix &);
friend matrix operator -(const matrix &, const maxtrix b);
friend matrix &operator *=(matrix &, const matrix &);
friend matrix operator * (const matrix &, const matrix &);
//read and write matrix
friend &ostream operator<<(ostream &, const matrix &);
friend &istream operator>>(isteam &, matrix &);
};
matrix :: matrix(int n_,int m) {
row=n_; col=m_;
}
matrix :: matrix(vector<vector<int>> &{
arr=a;
row=a.size();
col=a[0].size();
}
matrix &matrix :: operator = (const matrix &a) {
row=a.row; col=a.col;
arr=a.arr;
return *this;
}
matrix &operator +=(matrix &a, const matrix &b) {
for (int i=0;i<a.row;++i) {
for (int i=0;i<a.col;++i) {
a.arr[i][j]+=b.arr[i][j];
}
}
return a;
}
matrix operator + (const matrix &a,const matrix &b) {
matrix temp=a;
temp+=b;
return temp;
}
maxtrix &operator -=(matrix &a, const matrix &b) {
for (int i=0;i<a.row;++i) {
for (int i=0;i<a.col;++i) {
a.arr[i][j]-=b.arr[i][j];
}
}
return a;
}
matrix operator -(const matrix &a, const maxtrix &b) {
matrix temp=a;
temp-=b;
return temp;
}
matrix &operator *=(matrix &a, const matrix &b) {
matrix res(a.row,b.col);
for (int u = 0; u < a.row; u++)
for (int v = 0; v < b.col; v++)
for (int i = 0; i < a.row; i++)
res.arr[u][v] = ((int)arr[u][i] * b.arr[i][v] + res.arr[u][v] ) % MOD;
a=res;
return a;
}
matrix operator * (const matrix &a, const matrix &b) {
matrix temp;
temp=a;
temp*=b;
return temp;
}
istream &operator>>(istream &in, matrix &a) {
in>>a.row>>a.col;
for (int i=0;i<a.row;++i) {
for (int j=0;j<a.col;++j) {
cin>>a.arr[i][j];
}
}
return in;
}
ostream &operator<<(ostream &o , const matrix &a) {
for (int i=0;i<a.row;++i) {
for (int j=0;j<a.col;++j) {
cout<<a.arr[i][j]<<' ';
}
cout<<'\n';
}
return o;
}