一个控制程序终止的条件的设计问题
题目描述: 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时就终止程序






