-
Notifications
You must be signed in to change notification settings - Fork 0
/
54-4.c
58 lines (56 loc) · 1.22 KB
/
54-4.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int **mul(int **matrix,int m)
{
int i,j,k;
int **ans=(int **)malloc(sizeof(int *)*m);
for(i=0;i<m;i++)
{
ans[i]=(int *)malloc(sizeof(int)*m);
}
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
ans[i][j]=0;
for(k=0;k<m;k++)
{
ans[i][j]+=(matrix[k][i]*matrix[k][j]);
}
}
}
return ans;
}
int main()
{
int n,m,v,i,r,c,val,**ans,j;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&m,&v);
int **matrix=(int **)malloc(sizeof(int *)*m);
for(i=0;i<m;i++){
matrix[i]=(int *)malloc(sizeof(int)*m);
for(j=0;j<m;j++)
matrix[i][j]=0;
}
for(i=0;i<v;i++)
{
scanf("\n(%d:%d)=%d",&r,&c,&val);
matrix[c-1][r-1]=val;
}
ans=mul(matrix,m);
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf("%d",ans[i][j]);
if(j!=m-1)
printf(" ");
}
printf("\n");
}
}
return 0;
}