| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 861 人关注过本帖
标题:一个控制程序终止的条件的设计问题
只看楼主 加入收藏
静默编程
Rank: 2
等 级:论坛游民
帖 子:18
专家分:13
注 册:2017-3-8
结帖率:80%
收藏
 问题点数:0 回复次数:1 
一个控制程序终止的条件的设计问题
题目描述:
    This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns.
    这一次,你应该找到A + B,A和B是两个矩阵,然后计算零行和列的个数

输入:
    The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which are the number of rows and columns of the matrices, respectively. Then 2*M lines follow, each contains N integers in [-100, 100], separated by a space. The first M lines correspond to the elements of A and the second M lines to that of B.
    The input is terminated by a zero M and that case must NOT be processed.
    输入包含多个测试用例,每个始于一对正整数M和N(≤10),它们分别是矩阵的行和列的数量。然后是2 * M行,每个都包含N个整数,范围在[- 100,100]中,由空格隔开。第一个M行对应于A的元素和第二个M行与B的元素。
    输入被一个M是0终止,这个例子不能被处理

输出:
    For each test case you should output in one line the total number of zero rows and columns of A+B.

样例输入:
2 2
1 1
1 1
-1 -1
10 9
2 3
1 2 3
4 5 6
-1 -2 -3
-4 -5 -6
0
样例输出:
1
5


程序代码:
#include<stdio.h>
main()
{
    int m,n;
    while(scanf("%d%d",&m,&n)!=EOF&&m!=0)
    {
        int a[10][10];
        int b[10][10];
        int c[10][10];
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
            {
                scanf("%d",&a[i][j]);
            }
        
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                scanf("%d",&b[i][j]);
            }
            
        } 
        
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
            {
                c[i][j]=a[i][j]+b[i][j];
            }
        
        int num=0;
        int is0; 
        for(int i=0;i<m;i++)
            for(int j=0,is0=1;j<n&&is0;j++)
            {
                if(c[i][j])
                is0=0; 
                if(j==n-1)
                num++;
            }
        
        for(int j=0;j<n;j++)
            for(int i=0,is0=1;i<m&&is0;i++)
            {
                if(c[i][j])
                is0=0; 
                if(i==m-1)
                num++;
            }
        
        printf("%d\n",num);
    }
    return 0; 
}


关键就是怎样控制输入0时就终止程序
搜索更多相关主题的帖子: and the int For i++ 
2017-10-25 16:17
静默编程
Rank: 2
等 级:论坛游民
帖 子:18
专家分:13
注 册:2017-3-8
收藏
得分:0 
已经解决
2017-10-25 16:31
快速回复:一个控制程序终止的条件的设计问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015709 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved