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

3 
4