题解 | #矩阵乘法#

矩阵乘法

https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b

#include <iostream>

using namespace std;

#define fas(i,a,b) for(int i=a;i<b;++i)


const int NUM=100;
int m1[NUM][NUM];
int m2[NUM][NUM];
//int m3[NUM][NUM];

int main()
{
    int m,n,k;
    while(cin>>m>>n>>k)
    {
        fas(i,0,m)
            fas(j,0,n)
                cin>>m1[i][j];
        fas(i,0,n)
            fas(j,0,k)
                cin>>m2[i][j];
        // cout<<"********************************"<<endl;
        // // fas(i,0,n)
        // // {
        // //     fas(j,0,n)
        // //         cout<<m1[i][j]<<" ";
        // //     cout<<endl;
        // // }
        // cout<<"********************************"<<endl;
        fas(i,0,m)
        {
            fas(j,0,k)
            {
                int tmp=0;
                fas(i1,0,n)
                {
                    tmp+=m1[i][i1]*m2[i1][j];
                }
                //m3[i][j]=tmp;
                cout<<tmp<<" ";
            }
            cout<<endl;
        }
        //display matrix
        // fas(i,0,m)
        // {
        //     fas(j,0,k)
        //         cout<<m3[i][j]<<" ";
        //     cout<<endl;
        // }
        


    }
        
}

全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-30 18:19
点赞 评论 收藏
分享
爱睡觉的冰箱哥:学历不够啊兄弟,分析师都是9硕✌🏻咱搞不过他们滴
点赞 评论 收藏
分享
“校招”、“3-5年经验”
飞花断音:小公司招逆向的不要去,基本上都是搞黑灰产违法的东西
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务