fork download
  1. //(c)Terminator
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main(void){
  9. const int ROWS = 5;
  10. const int COLS = 4;
  11.  
  12. int mat[ROWS][COLS] = {
  13. { 1, 1, 0, 4 },
  14. { 2, 0, 3, 4 },
  15. { 3, 3, 3, 4 },
  16. { 4, 4, 3, 4 },
  17. { 5, 5, 3, 0 }
  18. };
  19.  
  20. int i, j;
  21. int rows = ROWS;
  22. int cols = COLS;
  23.  
  24. //вывод исходной матрицы
  25. for(i = 0; i < rows; ++i){
  26. for(j = 0; j < cols; ++j)
  27. cout << mat[i][j] << ' ';
  28. cout.put('\n');
  29. }
  30. cout.put('\n');
  31.  
  32.  
  33. //удаление
  34. for(i = 0; i < rows; ++i){
  35. for(j = 0; j < cols; ++j){
  36. if(mat[i][j] != 0)
  37. continue;
  38.  
  39. for(int r = 0; r < rows; ++r)
  40. memcpy(&mat[r][j], &mat[r][j + 1],(cols-(j+1))*sizeof(int));
  41.  
  42. //смещение строк
  43. for(int c = 0; c < cols; ++c){
  44. for(int r = i; r < (rows - 1); ++r)
  45. mat[r][c] = mat[r + 1][c];
  46. }
  47. --cols;
  48. --rows;
  49. --i;
  50. j = 0;
  51. }
  52. }
  53.  
  54. //вывод обработаной матрицы
  55. for(i = 0; i < rows; ++i){
  56. for(j = 0; j < cols; ++j)
  57. cout << mat[i][j] << ' ';
  58. cout.put('\n');
  59. }
  60. return 0;
  61. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1 1 0 4 
2 0 3 4 
3 3 3 4 
4 4 3 4 
5 5 3 0 

4 
5