Skip to content

Instantly share code, notes, and snippets.

@bxshi
Created April 18, 2012 01:26
Show Gist options
  • Save bxshi/2410357 to your computer and use it in GitHub Desktop.
Save bxshi/2410357 to your computer and use it in GitHub Desktop.
CareerCup 150 1.7 @1point3acres
/*
* CareerCup 150 4/16-4/22 1.1
*
* slaink@1point3acres
*
*/
/*
* 主要想到的就是遍历,不过加上几个flag,防止多次置零,同时当某行某列已经置零之后,跳过循环
* M*N 是m行n列吧……
*/
int martix[4][6]={1, 2, 3, 4, 5, 4,
6, 7, 8, 9, 0, 2,
1, 2, 3, 4, 5, 0,
1, 2, 8, 7, 6, 1};
void set_zero(int m, int n, int row, int column);
void check_matrix(int m, int n);
int main(int argc, char **argv)
{
int i,j;
check_matrix(4, 6);
return 0;
}
void check_matrix(int m, int n)
{
int *row;
int *column;
int i,j;
row = calloc(m, sizeof(int));
column = calloc(n, sizeof(int));
memset(row, 0, *row);
memset(column, 0, *column);
for(i=0;i<m;i++) {
for(j=0;j<n;j++) {
if(row[i] == 1)
break;
if(column[j] != 1) {
if(martix[i][j] == 0) {
row[i] = 1;
column[j] = 1;
set_zero(m, n, i, j);
}
}
}
}
for(i = 0; i<4;i++){
for(j = 0;j<6;j++)
printf("%d\t", martix[i][j]);
printf("\n");
}
/*之前忘记了*/
free(row);
free(column);
}
void set_zero(int m, int n, int row, int column)
{
int i;
for(i = 0; i < m; i++)
martix[i][column] = 0;
for(i = 0; i< n; i++)
martix[row][i] = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment