九度 题目1001:A+B for Matrices

注意到,是先输入行数(m), 再输入列数(n), 当m为0时终止程序


代码:

#include <iostream>

using namespace std;

int a[10][10];
int c[10][10];
int n, m;

int main()
{
	while (cin >> m >> n, n && m)
	{
		// input
		for (int i = 0; i < m; ++ i)
		{
			for (int j = 0; j < n; ++ j)
			{
				cin >> a[i][j];
			}
		}
		for (int i = 0; i < m; ++ i)
		{
			for (int j = 0; j < n; ++ j)
			{
				cin >> c[i][j];
				c[i][j] += a[i][j];
			}
		}
		// judge
		int zero_cnt = 0;
		// judge by row
		for (int i = 0; i < m; ++ i)
		{
			bool zero = true;			
			for (int j = 0; j < n; ++ j)
			{
				zero = zero && (c[i][j]==0);
			}
			zero_cnt = zero_cnt + (zero? 1: 0);
		}
		// judge by column
		for (int j = 0; j < n; ++ j)		
		{
			bool zero = true;			
			for (int i = 0; i < m; ++ i)
			{
				zero = zero && (c[i][j]==0);
			}
			zero_cnt = zero_cnt + (zero? 1: 0);
		}
		cout << zero_cnt << endl;
	}

	return 0;
}




你可能感兴趣的:(C++,九读,Jobdu)