Advertisement
RadioNurshat

Задача 7 Блока 1

Nov 10th, 2020
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.     int* arr = new int[n];
  9.  
  10.     int current = ((n % 2 == 0) ? n - 2 : n - 1);
  11.     int position = 0;
  12.     while (current >= 0) {//Слева направо до 0
  13.         arr[position] = current;
  14.         current -= 2;
  15.         position++;
  16.     }
  17.     position = n - 1;
  18.     current = ((n % 2 == 0) ? n - 1 : n - 2);
  19.     while (current >= 1) {//Справа налево до 1
  20.         arr[position] = current;
  21.         current -= 2;
  22.         position--;
  23.     }
  24.    
  25.    
  26.     for (int i = 0; i < n; i++) {
  27.         cout << i << " - " << arr[i] << endl;
  28.     }
  29.  
  30.     delete[] arr;
  31.  
  32.  
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement