Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class Matrix{
- public:
- Matrix(const int& n):n(n){
- m.resize(n, vector<int> (n));
- }
- void output () const{
- for(auto& i : m){
- for(auto& j : i)
- cout<<j<<' ';
- cout<<endl;
- }
- }
- Matrix operator *(const Matrix& m2){
- Matrix tmp(n);
- #pragma omp parallel for
- for(int i = 0; i <n; i++){
- for(int j = 0; j < n; j++){
- for(int k = 0; k < n; k++){
- tmp.m[i][j]+=m[i][k]*m2.m[k][j];
- }
- }
- }
- return tmp;
- }
- void in(){
- for(auto& i: m)
- for(auto& j: i)
- cin>>j;
- }
- private:
- int n;
- vector<vector<int> > m;
- };
- int main(){
- int n;
- cin>>n;
- Matrix m1(n);
- m1.in();
- Matrix m2(n);
- m2.in();
- Matrix m3(n);
- m3=m1*m2;
- cout<<endl;
- m1.output();
- cout<<endl;
- m2.output();
- cout<<endl;
- m3.output();
- return 0;
- }
- /*
- 3
- 1 2 1
- 3 0 4
- 1 3 2
- 4 2 0
- 1 -1 3
- 2 3 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement