台州ACM1744 矩阵计算_本为贵公子,平生实爱才_百度空间
时间限制(普通/Java):1000MS/10000MS 运行内存限制:65536KByte
总提交: 21    测试通过: 5

描述

输入

输出

样例输入

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;
}



郑重声明:资讯 【台州ACM1744 矩阵计算_本为贵公子,平生实爱才_百度空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——