实现
#include <cstdio>
#define MAXN 32
int chess[MAXN][MAXN];
int marks[MAXN][MAXN];
int main() {
int row, col;
scanf("%d%d",&row,&col);
for (int i = 0;i < row;++i) {
for (int j = 0;j < col;++j) {
scanf("%d",&chess[i][j]);
}
}
for (int i = 0;i < row;++i) {
int pre_val = 0;
int same_cnt = 0;
for (int j = 0;j < col;++j) {
if (pre_val == chess[i][j]) {
same_cnt+=1;
if (j == col - 1 && same_cnt >= 2) {
for (;same_cnt >= 0; --same_cnt) {
marks[i][j - same_cnt] = 1;
}
}
} else if (pre_val != chess[i][j]){
if(same_cnt >= 2) {
for (;same_cnt >= 0; --same_cnt) {
marks[i][j - same_cnt - 1] = 1;
}
}
same_cnt = 0;
}
pre_val = chess[i][j];
}
}
for (int j = 0;j < col;++j) {
int pre_val = 0;
int same_cnt = 0;
for (int i = 0;i < row;++i) {
if (pre_val == chess[i][j]) {
same_cnt+=1;
if ( i == row - 1 && same_cnt >= 2) {
for (;same_cnt >= 0; --same_cnt) {
marks[i - same_cnt][j] = 1;
}
}
} else if (pre_val != chess[i][j]) {
if (same_cnt >= 2) {
for (;same_cnt >= 0;--same_cnt) {
marks[i - same_cnt - 1][j] = 1;
}
}
same_cnt = 0;
}
pre_val = chess[i][j];
}
}
for (int i = 0;i < row;++i) {
for (int j = 0;j < col;++j) {
if (marks[i][j] == 1) {
printf("0 ");
} else {
printf("%d ",chess[i][j]);
}
}
printf("\n");
}
}