蓝桥杯矩阵乘法

#include<iostream>


using namespace std;


void input(long long array[],long long length);
void view(long long array[],long long length);
void getValue(long long array[],long long temp[],long long length);
long long getValue_temp(long long array[],long long temp[],long long length,long long row,long long colum);


int main(int argc,char** argv){

int M,N;
cin >> M >> N;
N = N - 1;

long long data[M * M];
long long temp[M * M];

input(data,M);

for(int i = 0;i < M * M;i++){

temp[i] = data[i];
}

while(N){

getValue(data,temp,M);
N--;
}

view(data,M);

return 0;
}


void input(long long array[],long long length){

for(long long i = 0;i < length * length;i++){

cin >> array[i];
}
}


void view(long long array[],long long length){

for(int i = 0;i < length * length;i++){

cout << array[i] << " ";

if((i + 1) % length == 0){

cout << endl;
}

}
}


void getValue(long long array[],long long temp[],long long length){

long long tt[length][length];
long long order = 0;

for(long long i = 0;i < length;i++){

for(long long j = 0;j < length;j++){

tt[i][j] = getValue_temp(array,temp,length,i,j);
}
}

for(long long i = 0;i < length;i++){

for(long long j = 0;j < length;j++){

array[order] = tt[i][j];
order++;
}
}
}


long long getValue_temp(long long array[],long long temp[],long long length,long long row,long long colum){

long long at[length][length];
long long tt[length][length];
long long sum = 0;

int order = 0;
for(long long i = 0;i < length;i++){

for(long long j = 0;j < length;j++){

at[i][j] = array[order];
order++;
}
}
order = 0;
for(long long i = 0;i < length;i++){

for(long long j = 0;j < length;j++){

tt[i][j] = temp[order];
order++;
}
}

for(long long i = 0;i < length;i++){

sum = sum + at[row][i] * tt[i][colum];
}

return sum;
}

posted @ 2018-05-19 20:27  IT蓝月  阅读(87)  评论(0编辑  收藏  举报
Live2D