水题
#include<iostream>
#include<cstring>
#define MAXSIZE 10
using namespace std;
int k;
class matrix
{
public:
int n;
int metric[MAXSIZE][MAXSIZE];
friend ostream& operator<<(ostream&out,matrix &a);
friend istream& operator>> (istream&in,matrix &a);
matrix operator *(matrix b);
matrix operator=(matrix b);
matrix()
{
memset(metric,0,sizeof(metric));
}
};
matrix matrix::operator *(matrix b)
{
matrix c;
c.n=this->n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
{
c.metric[i][j]=c.metric[i][j]+this->metric[i][k]*b.metric[k][j];
}
return c;
}
matrix matrix::operator=(matrix b)
{
this->n=b.n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
this->metric[i][j]=b.metric[i][j];
}
return *(this);
}
istream& operator>> (istream&in,matrix &a)
{
int n;
in>>n;
in>>k;
a.n=n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
in>>a.metric[i][j];
return in;
}
ostream& operator<<(ostream&out,matrix &a)
{
for(int i=0;i<a.n;i++){
for(int j=0;j<a.n;j++)
{
cout<<a.metric[i][j];
if(j!=a.n-1)cout<<" ";
}
cout<<endl; }
return out;
}
int main()
{
int t;
cin>>t;
while(t--)
{
matrix a,b,c;
cin>>a;
c=b=a;
k=k-1;
while(k--)
{
c=a*b;
b=c;
}
cout<<c;
}
}