Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void init(int**& arr, int hight, int width)
- {
- arr = new int*[hight];
- for(int i = 0; i < hight; i++)
- {
- arr[i] = new int[width];
- for(int j = 0; j < width; j++)
- {
- arr[i][j] = rand()%100;
- }
- }
- }
- void show(int** arr, int height, int width)
- {
- for(int i = 0; i < height; i++)
- {
- for(int j = 0; j < width; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- }
- void RowDeleteById(int**& arr, int& hight, int width, int id)
- {
- int** temp = new int*[hight-1];
- for(int i = 0; i < hight-1; i++)
- {
- if(i < id)
- temp[i] = arr[i];
- else
- temp[i] = arr[i+1];
- }
- delete[] arr;
- arr = temp;
- hight -= 1;
- }
- void ColDeleteById(int**& arr, int hight, int& width, int index)
- {
- int** temp = nullptr;
- init(temp, hight, width-1);
- for(int i = 0; i < hight; i++)
- {
- for(int j = 0; j < width-1; j++)
- {
- if(j < index)
- temp[i][j] = arr[i][j];
- else if(j >= index)
- temp[i][j] = arr[i][j+1];
- }
- }
- delete[] arr;
- arr = temp;
- width--;
- }
- void ManualDelete(int**& arr, int& hight, int& width)
- {
- int BigNum = arr[0][0];
- int BigNum_h = 0;
- int BigNum_v = 0;
- int SmallNum = arr[0][0];
- int SmallNum_h = 0;
- int SmallNum_v = 0;
- for(int i = 0; i < hight; i++)
- {
- for(int j = 0; j < width; j++)
- {
- if(arr[i][j] > BigNum)
- {
- BigNum = arr[i][j];
- BigNum_v = i;
- BigNum_h = j;
- }
- else if(arr[i][j] < SmallNum)
- {
- SmallNum = arr[i][j];
- SmallNum_v = i;
- SmallNum_h = j;
- }
- }
- }
- if(BigNum_v == SmallNum_v)
- {
- RowDeleteById(arr, hight, width, BigNum_v);
- if(BigNum_h > SmallNum_h)
- {
- ColDeleteById(arr, hight, width, BigNum_h);
- ColDeleteById(arr, hight, width, SmallNum_h);
- }
- else
- {
- ColDeleteById(arr, hight, width, SmallNum_h);
- ColDeleteById(arr, hight, width, BigNum_h);
- }
- }
- else if(BigNum_h == SmallNum_h)
- {
- ColDeleteById(arr, hight, width, BigNum_h);
- if(BigNum_v > SmallNum_v)
- {
- RowDeleteById(arr, hight, width, BigNum_v);
- RowDeleteById(arr, hight, width, SmallNum_v);
- }
- else
- {
- RowDeleteById(arr, hight, width, SmallNum_v);
- RowDeleteById(arr, hight, width, BigNum_v);
- }
- }
- else
- {
- if(BigNum_v > SmallNum_v)
- {
- RowDeleteById(arr, hight, width, BigNum_v);
- RowDeleteById(arr, hight, width, SmallNum_v);
- }
- else
- {
- RowDeleteById(arr, hight, width, SmallNum_v);
- RowDeleteById(arr, hight, width, BigNum_v);
- }
- if(BigNum_h > SmallNum_h)
- {
- ColDeleteById(arr, hight, width, BigNum_h);
- ColDeleteById(arr, hight, width, SmallNum_h);
- }
- else
- {
- ColDeleteById(arr, hight, width, SmallNum_h);
- ColDeleteById(arr, hight, width, BigNum_h);
- }
- }
- }
- int main()
- {
- srand(time(0));
- int hight = 5;
- int width = 5;
- int** array = nullptr;
- init(array, hight, width);
- show(array, hight, width);
- cout << endl;
- ManualDelete(array, hight, width);
- cout << endl;
- show(array, hight, width);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement