爲什麼我的只能10個過八個 求解

題目描述:

    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.

輸入:

    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.

輸出:

    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>
#include <stdlib.h>
int nM,nN;
int i,j,tmp,cZero=0;
int **pMat=NULL;
void release()
{
	for(i=0;i<nN;i++)
		free(pMat[i]);
	free(pMat);
}
void create()
{
	pMat=(int **)malloc(nN*sizeof(int*));
	for(i=0;i<nN;i++)
		pMat[i]=(int *)malloc(nM*sizeof(int));
}
void input()
{
	for(i=0;i<nN;i++)
		for(j=0;j<nM;j++)
			scanf("%d",&pMat[i][j]);
}
void input2()
{
	tmp=0;
	for(i=0;i<nN;i++)
		for(j=0;j<nM;j++)
		{
			scanf("%d",&tmp);
			pMat[i][j]+=tmp;
		}
}
void judge()
{
	cZero=0;
	for(i=0;i<nN;i++)
	{
		for(j=0;j<nM;j++)
		{
			if(pMat[i][j]!=0)
				break;
			else if(j==nM-1)
				cZero++;
		}
	}
	for(i=0;i<nM;i++)
	{
		for(j=0;j<nN;j++)
		{
			if(pMat[j][i]!=0)
				break;
			else if(j==nN-1)
				cZero++;
		}
	}
}
int main()
{
	while(scanf("%d",&nM)&&nM!=0)
	{
		scanf("%d",&nN);
		if(nN==0) return 0;
		create();
		input();
		input2();
		judge();
		printf("%d\n",cZero);
		release();
	}
	return 0;
}

至今還不知道另外2個爲什麼不能通過 ,求指教
發佈了24 篇原創文章 · 獲贊 11 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章