Advertisement
Bertran_rz

CW 15.10

Oct 15th, 2021 (edited)
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void init(int**& arr, int hight, int width)
  6. {
  7.     arr = new int*[hight];
  8.  
  9.     for(int i = 0; i < hight; i++)
  10.     {
  11.         arr[i] = new int[width];
  12.         for(int j = 0; j < width; j++)
  13.         {
  14.             arr[i][j] = rand()%100;
  15.         }
  16.     }
  17. }
  18.  
  19.  
  20. void show(int** arr, int height, int width)
  21. {
  22.     for(int i = 0; i < height; i++)
  23.     {
  24.         for(int j = 0; j < width; j++)
  25.         {
  26.             cout << arr[i][j] << " ";
  27.         }
  28.         cout << endl;
  29.     }
  30. }
  31.  
  32.  
  33. void RowDeleteById(int**& arr, int& hight, int width, int id)
  34. {
  35.     int** temp = new int*[hight-1];
  36.    
  37.  
  38.     for(int i = 0; i < hight-1; i++)
  39.     {
  40.         if(i < id)
  41.                 temp[i] = arr[i];
  42.         else
  43.             temp[i] = arr[i+1];
  44.     }
  45.  
  46.     delete[] arr;
  47.  
  48.     arr = temp;
  49.  
  50.     hight -= 1;
  51. }
  52.  
  53. void ColDeleteById(int**& arr, int hight, int& width, int index)
  54. {
  55.     int** temp = nullptr;
  56.    
  57.     init(temp, hight, width-1);
  58.  
  59.     for(int i = 0; i < hight; i++)
  60.     {
  61.         for(int j = 0; j < width-1; j++)
  62.         {
  63.             if(j < index)
  64.                 temp[i][j] = arr[i][j];
  65.             else if(j >= index)
  66.                 temp[i][j] = arr[i][j+1];
  67.         }
  68.     }
  69.     delete[] arr;
  70.  
  71.     arr = temp;
  72.     width--;
  73. }
  74.  
  75.  
  76. void ManualDelete(int**& arr, int& hight, int& width)
  77. {
  78.     int BigNum = arr[0][0];
  79.     int BigNum_h = 0;
  80.     int BigNum_v = 0;
  81.     int SmallNum = arr[0][0];
  82.     int SmallNum_h = 0;
  83.     int SmallNum_v = 0;
  84.  
  85.     for(int i = 0; i < hight; i++)
  86.     {
  87.         for(int j = 0; j < width; j++)
  88.         {
  89.             if(arr[i][j] > BigNum)
  90.             {
  91.                 BigNum = arr[i][j];
  92.                 BigNum_v = i;
  93.                 BigNum_h = j;
  94.             }
  95.             else if(arr[i][j] < SmallNum)
  96.             {
  97.                 SmallNum = arr[i][j];
  98.                 SmallNum_v = i;
  99.                 SmallNum_h = j;
  100.             }
  101.         }
  102.     }
  103.  
  104.     if(BigNum_v == SmallNum_v)
  105.     {
  106.         RowDeleteById(arr, hight, width, BigNum_v);
  107.  
  108.         if(BigNum_h > SmallNum_h)
  109.         {
  110.             ColDeleteById(arr, hight, width, BigNum_h);
  111.             ColDeleteById(arr, hight, width, SmallNum_h);
  112.         }
  113.         else
  114.         {
  115.             ColDeleteById(arr, hight, width, SmallNum_h);
  116.             ColDeleteById(arr, hight, width, BigNum_h);
  117.         }
  118.     }
  119.  
  120.     else if(BigNum_h == SmallNum_h)
  121.     {
  122.         ColDeleteById(arr, hight, width, BigNum_h);
  123.  
  124.         if(BigNum_v > SmallNum_v)
  125.         {
  126.             RowDeleteById(arr, hight, width, BigNum_v);
  127.             RowDeleteById(arr, hight, width, SmallNum_v);
  128.         }
  129.         else
  130.         {
  131.             RowDeleteById(arr, hight, width, SmallNum_v);
  132.             RowDeleteById(arr, hight, width, BigNum_v);
  133.         }
  134.     }
  135.     else
  136.     {
  137.         if(BigNum_v > SmallNum_v)
  138.         {
  139.             RowDeleteById(arr, hight, width, BigNum_v);
  140.             RowDeleteById(arr, hight, width, SmallNum_v);
  141.  
  142.         }
  143.         else
  144.         {
  145.             RowDeleteById(arr, hight, width, SmallNum_v);
  146.             RowDeleteById(arr, hight, width, BigNum_v);
  147.         }
  148.  
  149.         if(BigNum_h > SmallNum_h)
  150.         {
  151.             ColDeleteById(arr, hight, width, BigNum_h);
  152.             ColDeleteById(arr, hight, width, SmallNum_h);
  153.         }
  154.         else
  155.         {
  156.             ColDeleteById(arr, hight, width, SmallNum_h);
  157.             ColDeleteById(arr, hight, width, BigNum_h);
  158.         }
  159.     }
  160. }
  161.  
  162. int main()
  163. {
  164.     srand(time(0));
  165.     int hight = 5;
  166.     int width = 5;
  167.     int** array = nullptr;
  168.  
  169.     init(array, hight, width);
  170.     show(array, hight, width);
  171.     cout << endl;
  172.     ManualDelete(array, hight, width);
  173.     cout << endl;
  174.     show(array, hight, width);
  175.    
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement