设为首页 加入收藏

TOP

NYOJ 623 A*B Problem II
2015-07-20 17:33:21 来源: 作者: 【 】 浏览:2
Tags:NYOJ 623 Problem

/*
题目大意:矩阵与矩阵的相乘
解题思路:模拟矩阵的乘法
关键点:模拟
解题人:lingnichong
解题时间:2104-10-04 17:21:00
解题体会:按照题目要求写下来即可
*/


A*B Problem II

时间限制:1000 ms | 内存限制:65535 KB 难度:1
描述
ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大量的乘法都会把他搞乱,所以他想请你写个程序帮他检验一下计算结果是否正确。
输入
有多组测试数据,每行给出一组m,n,k(0 矩阵A:m行n列。
矩阵B:n行k列。
接下来给出m*n个数表示矩阵A和n*k个数表示矩阵B,对于每个数s,0<=s<=1000。
当m,n,k同时为0时结束。
输出
计算两个矩阵的乘积并输出。
样例输入
2 1 3
1
2
1 2 3
2 2 3
1 2
3 4
1 0 1
0 1 0
0 0 0
样例输出
1 2 3
2 4 6
1 2 1
3 4 3

来源
szhhck的水库


#include
      
       
int a[55][55],b[55][55],c[55][55];
int main()
{
    int m,n,k,i,j,s;
    int sum;
    while(scanf("%d%d%d",&m,&n,&k),m||n||k)
    {
       /*********输入两个矩阵*********/ 
        for(i = 0; i < m; i++)
        {
            for(j = 0; j < n; j++)
            scanf("%d",&a[i][j]);
        }    
        for(i = 0; i < n; i++)
        {
            for(j = 0; j < k; j++)
            scanf("%d",&b[i][j]);
        } 
       /***********对两个矩阵乘积*************/ 
        for(i = 0; i < m; i++)
        {
            
            for(j = 0; j < k; j++)
            {
                sum=0;
                for(s = 0; s < n; s++)
                sum += a[i][s]*b[s][j];
                c[i][j]=sum;
            }    
        }    
       /*********输出结果*********/ 
      // printf("\n");
        for(i = 0; i < m; i++)
        {
            for(j = 0; j < k; j++)
            printf("%d ",c[i][j]);
            printf("\n");
        }    
       // printf("\n");
    }    
    return 0;
}  
      




<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力??
上一篇: HDU 3829 Cat VS Dog
下一篇: C++中使用Json的方法
相关文章
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<script> (function(){ var appid = 'cyrBEfE7C', conf = 'prod_830794cf494da8b808afb2994cfe0fee'; var doc = document, s = doc.createElement('script'), h = doc.getElementsByTagName('head')[0] || doc.head || doc.documentElement; s.type = 'text/java script'; s.charset = 'utf-8'; s.src = 'http://assets.changyan.sohu.com/upload/changyan.js?conf='+ conf +'&appid=' + appid; h.insertBefore(s,h.firstChild); window.SCS_NO_IFRAME = true; })()
<script type="text/java script">BAIDU_CLB_fillSlot("771057");
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 3830 Checkers 下一篇BNUOJ34973Liserious战队

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·JAVA现在的就业环境 (2025-12-26 01:19:24)
·最好的java反编译工 (2025-12-26 01:19:21)
·预测一下2025年Java (2025-12-26 01:19:19)
·Libevent C++ 高并发 (2025-12-26 00:49:30)
·C++ dll 设计接口时 (2025-12-26 00:49:28)