描述
输入
输出
样例输入
1
3 3
1 0 0
0 1 0
0 0 1
3 3
1 2 3
1 2 3
1 2 3
-
*
=
+
end
样例输出
0 -2 -3
-1 -1 -3
-1 -2 -2
1 2 3
1 2 3
1 2 3
2 4 6
2 4 6
2 4 6
题目上传者
crq
#include <stdio.h>
int main()
{
char s[4];
int z, i, j, k;
int a[10][10], b[10][10], c[10][10];
int a_r, a_c, b_r, b_c, c_r, c_c;
scanf("%d", &z);
while (z--){
scanf("%d %d", &a_r, &a_c);
for (i=0; i<a_r; i++)
for (j=0; j<a_c; j++)
scanf("%d", &a[i][j]);
scanf("%d %d", &b_r, &b_c);
for (i=0; i<b_r; i++)
for (j=0; j<b_c; j++)
scanf("%d", &b[i][j]);
while (scanf("%s", s) == 1){
if (s[0] == 'e') break;
if (s[0] == '='){
for (i=0; i<a_r; i++)
for (j=0; j<a_c; j++)
a[i][j] = b[i][j];
}
else if (s[0] == '+'){
for (i=0; i<a_r; i++){
for (j=0; j<a_c-1; j++)
printf("%d ", a[i][j]+b[i][j]);
printf("%d\n", a[i][j]+b[i][j]);
}
printf("\n");
}
else if (s[0] == '-'){
for (i=0; i<a_r; i++){
for (j=0; j<a_c-1; j++)
printf("%d ", a[i][j]-b[i][j]);
printf("%d\n", a[i][j]-b[i][j]);
}
printf("\n");
}
else{
c_r = a_r;
c_c = b_c;
for (i=0; i<c_r; i++)
for (j=0; j<c_c; j++){
c[i][j] = 0;
for (k=0; k<a_c; k++)
c[i][j] += a[i][k]*b[k][j];
}
for (i=0; i<c_r; i++){
for (j=0; j<c_c-1; j++)
printf("%d ", c[i][j]);
printf("%d\n", c[i][j]);
}
printf("\n");
}
}
}
return 0;
}