#include <iostream> using namespace std; int main() { int m, n; while (cin >> m) { if(m==0)break; cin>>n; //输入两个矩阵 int a[m][n], b[m][n],res[m][n]; 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 >> b[i][j]; //矩阵相加 for(int i =0;i<m;i++) for(int j =0;j<n;j++) res[i][j] = a[i][j]+b[i][j]; int zeroRow = 0,zeroColumn = 0; for(int i =0;i<m;i++){ bool isAllZero = 1; for(int j =0;j<n;j++){ if(res[i][j] != 0){ isAllZero = 0; break; } } if(isAllZero)zeroRow++; } for(int j =0;j<n;j++){ bool isAllZero = 1; for(int i =0;i<m;i++){ if(res[i][j] != 0){ isAllZero = 0; break; } } if(isAllZero)zeroColumn++; } cout<<zeroRow+zeroColumn<<endl; } } // 64 位输出请用 printf("%lld")
写的有点繁了