jedyu
2014-02-14 14:21:03 +08:00
#include <iostream>
using namespace std;
void setZero(int mat[3][4], int m, int n)
{
if (NULL == mat || 0 ==m || n == 0)
{
return;
}
bool row[m], col[n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (mat[i][j] == 0)
{
row[i] = true;
col[j] = true;
}
}
}
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
if (row[i] || col[j])
{
mat[i][j] = 0;
}
}
}
}
int main(int argc, char const *argv[])
{
int mat[3][4] = { 1, 2, 0, 4,
4, 0, 8, 10,
3, 8, 0, 12 };
setZero(mat, 3, 4);
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 4; ++j)
{
cout << mat[i][j] << ' ';
}
cout << endl;
}
return 0;
}