#include <iostream>

using namespace std;

class Matrix{
private:
int r;
int c;
int **a;
public:
Matrix(){
this -> r = 0;
this -> c = 0;
this -> a = NULL;
}
Matrix(int mr, int mc, int **a){
this -> r = mr;
this -> c = mc;
this -> a = new int*[];
}
friend istream & operator >> (istream &is, Matrix &p){
if(p.a != NULL)
delete []p.a;
is >> p.r;
is >> p.c;
p.a = new int * [p.r];
for(int i = 0; i < p.r; i++){
p.a[i] = new int [p.c];
}
for(int i = 0; i < p.r; i++){
for(int j = 0; j < p.c; j++){
is >> p.a[i][j];
}
}
return is;
}
friend ostream & operator << (ostream &os, const Matrix &p){
os << p.r;
os << p.c;
for(int i = 0; i < p.r; i++){
for(int j = 0; j < p.c; j++){
os << p.a[i][j];
}
}
return os;
}
Matrix operator + (const Matrix &p){
for(int i = 0; i < p.r; i++){
for(int j = 0; j < p.c; j++){
this -> a[i][j] = a[i][j] + p.a[i][j];
}
}
return (*this);
}
Matrix operator * (int n){
for(int i = 0; i < this -> r; i++){
for(int j = 0; j < this -> c; j++){
this -> a[i][j] = n * a[i][j];
}
}
return (*this);
}
Matrix operator * (const Matrix &p){
Matrix mt3;
mt3.r = this -> r;
mt3.c = p.c;
mt3.a = new int * [this -> r];
for(int i = 0; i < this -> r; i++){
mt3.a[i] = new int [p.c];
}
for(int i = 0; i < mt3.r; i++){
for(int j = 0; j < mt3.c; j++){
mt3.a[i][j] = 0;
for(int k = 0; j < mt3.c; k++){
mt3.a[i][j] += (a[i][k] * p.a[k][i]);
}
}
}
return mt3;
}
Matrix operator = (const Matrix &p){
if(this -> a != NULL){
for(int i = 0; i < this -> r; i++){
delete []a[i];
delete []a;
}
this -> r = p.r;
this -> c = p.c;
this -> a = new int * [this -> r];
for(int i = 0; i < this -> r; i++){
this -> a[i] = new int [this -> c];
}
for(int i = 0; i < this -> r; i++){
for(int j= 0; j < this -> c; j++){
this -> a[i][j] = p.a[i][j];
}
}
return (*this);
}
}
void print(){
for(int i = 0; i < this -> r; i++){
for(int j = 0; j < this -> c; j++){
cout << a[i][j] << " ";
}
cout << endl;
}
}
};

int main(){
Matrix mt1;
Matrix mt2;
Matrix mt3;
/*int n;
cout << "Nhap n: ";
cin >> n;*/
cout << "Nhap ma tran: ";
cin >> mt1;
mt1.print();
cout << "----0.0----" << endl;
cout << "Nhap ma tran: ";
cin >> mt2;
mt2.print();
/*cout << "----0.0----" << endl;
mt3 = mt1 * n;
mt3.print();*/
//cout << "----0.0----" << endl;
//mt3 = mt1 + mt2;
//mt3.print();
cout << "----0.0----" << endl;
mt3 = mt1 * mt2;
mt3.print();
cout << "----0.0----" << endl;
mt3 = (mt1 = mt2);
mt3.print();
}