Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- using namespace std;
- // выше главной
- int* GetUpperLine(int** a, int n, int i)
- {
- int * currentArray = new int[n - i - 1];
- for (int j = 0; j < n - i - 1; ++j)
- currentArray[j] = a[j][j + i + 1];
- return currentArray;
- //for (int j = 0; j < n - i - 1; ++j)
- //cout << currentArray[j] << "\t";
- //cout << endl;
- }
- void InsertUpper(int** a, int * mas, int n, int i)
- {
- for (int j = 0; j < n - i - 1; ++j)
- a[j][j + i + 1] = mas[j];
- }
- //ниже главной
- int* GetlowerLine(int** a, int n, int i)
- {
- int * currentArray = new int[n - i - 1];
- for (int j = 0; j < n - i - 1; ++j)
- currentArray[j] = a[j + i + 1][j];
- return currentArray;
- }
- void InsertLower(int** a, int * mas, int n, int i)
- {
- for (int j = 0; j < n - i - 1; ++j)
- a[j + i + 1][j] = mas[j];
- }
- void Sort(int * a, int n)
- {
- for (int i = 0; i < n - 1; ++i)
- for (int j = i; j < n; ++j)
- {
- if (a[i] < a[j])
- swap(a[i], a[j]);
- }
- }
- void SortGreater(int * a, int n)
- {
- for (int i = 0; i < n - 1; ++i)
- for (int j = i; j < n; ++j)
- {
- if (a[i] > a[j])
- swap(a[i], a[j]);
- }
- }
- int main()
- {
- int n; cin >> n;
- int **a = new int*[n];
- for (int i = 0; i < n; ++i)
- a[i] = new int[n];
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- cin >> a[i][j];
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j)
- cout << a[i][j] << "\t";
- cout << endl;
- }
- cout << endl;
- for (int i = 0; i < n - 1; ++i)
- {
- int size = n - i - 1;
- int * mas = new int[size];
- //ниже главной
- mas = GetlowerLine(a, n, i);
- Sort(mas, size);
- InsertLower(a, mas, n, i);
- //выше главной
- mas = GetUpperLine(a, n, i);
- SortGreater(mas, size);
- InsertUpper(a, mas, n, i);
- }
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j)
- cout << a[i][j] << "\t";
- cout << endl;
- }
- cout << endl;
- /*
- 4
- 1 12 8 4
- 5 6 2 3
- 9 10 11 7
- 13 14 15 16
- */
- //system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement