fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. void DeleteNullRow(int** a, int& rows, int cols)
  7. {
  8. int newRow = 0;
  9. for(int j = 0; j < rows; ++j)
  10. {
  11. bool has0 = false;
  12. for(int i = 0; i < cols; ++i)
  13. if (a[j][i] == 0) { has0 = true; break; }
  14. if (!has0)
  15. {
  16. for(int i = 0; i < cols; ++i)
  17. a[newRow][i] = a[j][i];
  18. newRow++;
  19. }
  20. }
  21. for(int i = newRow; i < rows; ++i) delete[] a[i];
  22. rows = newRow;
  23. }
  24.  
  25.  
  26. int main(int argc, const char * argv[])
  27. {
  28. int rows = 10;
  29. int **a = new int*[rows];
  30. for(int i = 0; i < rows; ++i)
  31. {
  32. a[i] = new int[20];
  33. for(int j = 0; j < 20; ++j) a[i][j] = rand()%20;
  34. }
  35.  
  36. for(int i = 0; i < rows; ++i)
  37. {
  38. for(int j = 0; j < 20; ++j) cout << setw(2) << a[i][j] << " ";
  39. cout << endl;
  40. }
  41. cout << endl;
  42. cout << endl;
  43.  
  44. DeleteNullRow(a, rows, 20);
  45.  
  46. for(int i = 0; i < rows; ++i)
  47. {
  48. for(int j = 0; j < 20; ++j) cout << setw(2) << a[i][j] << " ";
  49. cout << endl;
  50. }
  51.  
  52. }
  53.  
Success #stdin #stdout 0s 4424KB
stdin
Standard input is empty
stdout
 3  6 17 15 13 15  6 12  9  1  2  7 10 19  3  6  0  6 12 16 
11  8  7  9  2 10  2  3  7 15  9  2  2 18  9  7 13 16 11  2 
 9 13  1 19  4 17 18  4 15 10 13  6 11  0 16 13  2 10 16  1 
 5  5  4  7 16  5  6  9 13 17  4 15  2  5 14  7 14  4  3 10 
 7  8 16 18  8  4  3 11 14 19 12  0 16  8 19 12  6  6 14 19 
15 10 14 18  7  1 17  2 17 12 12 16  1  0  6  1  5  9  4 19 
 0  9 11 17 17 11  1 15  9  7  7 16 17 13  6  5  6  3 19  4 
 8 11 12  9  3 19 10  8  8 15  0  9 16  3 18  5  6 11  1 15 
19  8  4  8  1 10 13  0 14  4  4 14  7 16  3 11  7  5 19 16 
12 11 17  8 15  7 14  1 18 15  9 17 15 13 18  8  3 11  8  9 


11  8  7  9  2 10  2  3  7 15  9  2  2 18  9  7 13 16 11  2 
 5  5  4  7 16  5  6  9 13 17  4 15  2  5 14  7 14  4  3 10 
12 11 17  8 15  7 14  1 18 15  9 17 15 13 18  8  3 11  8  9