Advertisement
Bertran_rz

Untitled

Oct 15th, 2021
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void ManualDelete(int**& arr, int& hight, int width)
  6. {
  7.     int counter = 0;
  8.     for(int i = 0; i < hight; i++)
  9.     {
  10.         int mini_counter = 0;
  11.         for(int j = 0; j < width; j++)
  12.         {
  13.             if(arr[i][j]%2 == 0) mini_counter++;
  14.         }
  15.         if(mini_counter > 3)
  16.             counter++;
  17.     }
  18.  
  19.     int** temp = new int*[hight-counter];
  20.  
  21.     for(int i = 0, c = 0; i < hight; i++)
  22.     {
  23.         int mini_counter = 0;
  24.         for(int j = 0; j < width; j++)
  25.         {
  26.             if(arr[i][j]%2==0) mini_counter++;
  27.         }
  28.        
  29.         if(mini_counter <= 3)
  30.         {
  31.             temp[c] = arr[i];
  32.             c++;
  33.         }
  34.     }
  35.  
  36.     delete[] arr;
  37.  
  38.     arr = temp;
  39.  
  40.     hight -= counter;
  41. }
  42.  
  43. void init(int**& arr, int hight, int width)
  44. {
  45.     arr = new int*[hight];
  46.  
  47.     for(int i = 0; i < hight; i++)
  48.     {
  49.         arr[i] = new int[width];
  50.         for(int j = 0; j < width; j++)
  51.         {
  52.             arr[i][j] = rand()%100;
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58. void show(int** arr, int height, int width)
  59. {
  60.     for(int i = 0; i < height; i++)
  61.     {
  62.         for(int j = 0; j < width; j++)
  63.         {
  64.             cout << arr[i][j] << " ";
  65.         }
  66.         cout << endl;
  67.     }
  68. }
  69.  
  70. int main()
  71. {
  72.     int hight = 5;
  73.     int width = 5;
  74.     int** array = nullptr;
  75.  
  76.     init(array, hight, width);
  77.     show(array, hight, width);
  78.     cout << endl;
  79.     ManualDelete(array, hight, width);
  80.     cout << endl;
  81.     show(array, hight, width);
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement