fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a[100][100]={0},row, col;
  6. cin>>row>>col;
  7. for(int i = 1; i <= row; i++){
  8. for(int j = 1; j <= col; j++){
  9. cin>>a[i][j];
  10. }
  11. }
  12. for(int i = 1; i <= row; i++){
  13. for(int j = 1; j <= col; j++){
  14. if(!a[i - 1][j] && !a[i][j + 1] && !a[i + 1][j] && !a[i][j - 1])
  15. a[i][j] = 0;
  16. }
  17. }
  18. for(int i = 1; i <= row; i++){
  19. for(int j = 1; j <= col; j++){
  20. cout<<a[i][j]<<" ";
  21. }
  22. cout<<endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 3100KB
stdin
4 5
1 0 0 1 0
0 1 0 1 0
1 0 0 1 0
0 0 0 1 0
stdout
0 0 0 1 0 
0 0 0 1 0 
0 0 0 1 0 
0 0 0 1 0