Advertisement
Infiniti_Inter

<3

Apr 23rd, 2020
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. // выше главной
  8. int* GetUpperLine(int** a, int n, int i)
  9. {
  10.     int * currentArray = new int[n - i - 1];
  11.     for (int j = 0; j < n - i - 1; ++j)
  12.         currentArray[j] = a[j][j + i + 1];
  13.     return currentArray;
  14.     //for (int j = 0; j < n - i - 1; ++j)
  15.         //cout << currentArray[j] << "\t";
  16.     //cout << endl;
  17. }
  18. void InsertUpper(int** a, int * mas, int n, int i)
  19. {
  20.     for (int j = 0; j < n - i - 1; ++j)
  21.         a[j][j + i + 1] = mas[j];
  22. }
  23.  
  24. //ниже главной
  25. int* GetlowerLine(int** a, int n, int i)
  26. {
  27.     int * currentArray = new int[n - i - 1];
  28.     for (int j = 0; j < n - i - 1; ++j)
  29.         currentArray[j] = a[j + i + 1][j];
  30.     return currentArray;
  31. }
  32. void InsertLower(int** a, int * mas, int n, int i)
  33. {
  34.     for (int j = 0; j < n - i - 1; ++j)
  35.         a[j + i + 1][j] = mas[j];
  36. }
  37.  
  38.  
  39. void Sort(int * a, int n)
  40. {
  41.     for (int i = 0; i < n - 1; ++i)
  42.         for (int j = i; j < n; ++j)
  43.         {
  44.             if (a[i] < a[j])
  45.                 swap(a[i], a[j]);
  46.         }
  47. }
  48.  
  49. void SortGreater(int * a, int n)
  50. {
  51.     for (int i = 0; i < n - 1; ++i)
  52.         for (int j = i; j < n; ++j)
  53.         {
  54.             if (a[i] > a[j])
  55.                 swap(a[i], a[j]);
  56.         }
  57. }
  58.  
  59.  
  60. int main()
  61. {
  62.     int n; cin >> n;
  63.     int **a = new int*[n];
  64.     for (int i = 0; i < n; ++i)
  65.         a[i] = new int[n];
  66.     for (int i = 0; i < n; ++i)
  67.         for (int j = 0; j < n; ++j)
  68.             cin >> a[i][j];
  69.  
  70.     for (int i = 0; i < n; ++i) {
  71.         for (int j = 0; j < n; ++j)
  72.             cout << a[i][j] << "\t";
  73.         cout << endl;
  74.     }
  75.     cout << endl;
  76.  
  77.     for (int i = 0; i < n - 1; ++i)
  78.     {
  79.         int size = n - i - 1;
  80.         int * mas = new int[size];
  81.         //ниже главной
  82.         mas = GetlowerLine(a, n, i);
  83.         Sort(mas, size);
  84.         InsertLower(a, mas, n, i);
  85.  
  86.         //выше главной
  87.         mas = GetUpperLine(a, n, i);
  88.         SortGreater(mas, size);
  89.         InsertUpper(a, mas, n, i);
  90.  
  91.  
  92.     }
  93.  
  94.     for (int i = 0; i < n; ++i) {
  95.         for (int j = 0; j < n; ++j)
  96.             cout << a[i][j] << "\t";
  97.         cout << endl;
  98.  
  99.     }
  100.     cout << endl;
  101.  
  102.     /*
  103.         4
  104.         1 12 8 4
  105.         5 6 2 3
  106.         9 10 11 7
  107.         13 14 15 16
  108.     */
  109.  
  110.     //system("pause");
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement