Advertisement
RickMortynson

Untitled

Dec 10th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. void show_Ary(int **Ary, int num) {
  7.     for (int i = 0; i < num; i++) {
  8.         for (int j = 0; j < num; j++) {
  9.             cout << setw(3) << Ary[i][j];
  10.         }
  11.         cout << endl;
  12.     }
  13.  
  14. }
  15.  
  16.  
  17. int* generate_first_Ary(int num) {
  18.     int *tempAry = new int[num*num];
  19.     for (int i = 0; i < (num)*(num); i++) {
  20.         tempAry[i] = -(num)+rand() % (num - (-num) + 1); // формула для получения случайного числа от min до max
  21.         cout << "Никита лох ";
  22.     }
  23.     return tempAry;
  24. }
  25.  
  26. void sort_first_Ary(int *tempAry, int num) {
  27.     bool ok = false;
  28.     int temp;
  29.     while (!ok) {
  30.         ok = true;
  31.         for (int k = 0; k < (num)*(num); k++) {
  32.             if (tempAry[k] < tempAry[k + 1]) {
  33.                 temp = tempAry[k];
  34.                 tempAry[k] = tempAry[k + 1];
  35.                 tempAry[k + 1] = temp;
  36.                 ok = false;
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. int** generate_second_Ary(int* tempAry, int num) {
  43.     int **Ary = new int*[num];
  44.     for (int i = 0; i < num; i++) {
  45.         Ary[i] = new int[num];
  46.     }
  47.     int counter = 0;
  48.  
  49.     for (int i = 0; i < num; i++) {
  50.         for (int j = 0; j < num; j++) {
  51.             Ary[i][j] = 0;
  52.         }
  53.     }
  54.  
  55.     for (int i = 0; i < num; i++) {
  56.         for (int j = 0; j < num; j++) {
  57.             if (i % 2 == 0) {
  58.                 Ary[j][i] = tempAry[counter];
  59.             }
  60.             else {
  61.                 Ary[(num - 1) - j][i] = tempAry[counter];
  62.             }
  63.             counter++;
  64.         }
  65.     }
  66.     return Ary;
  67. }
  68.  
  69. int main() {
  70.     setlocale(LC_ALL, "rus");
  71.     srand(time(0));
  72.     int N;
  73.     cout << "Введите N ";
  74.     cin >> N;
  75.     int *tempAry = generate_first_Ary(N + 15);
  76.     sort_first_Ary(tempAry, N + 15);
  77.     int **Ary = generate_second_Ary(tempAry, N + 15);
  78.     show_Ary(Ary, N + 15);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement