avr39-ripe

arrFloatZeros

Apr 6th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     const int arrSize = 10;
  9.     int arr[arrSize] = { 0,1,2,0,0,3,0,4,0,0 };
  10.     //  int arr[arrSize] = {1,2,3,0,0,4,0,5,0,6};
  11.     //  int arr[arrSize]={0};
  12.     //  int arr[arrSize]={1,2,3,4,5,6,7,8,9,10};
  13.     for (int i = 0; i < arrSize; i++) { cout << arr[i] << " "; }    cout << endl;
  14.  
  15.     for (int tail = arrSize - 1, head = tail - 1; head >= 0; tail--, head--)
  16.     {
  17.         for (; arr[tail] && tail > 1; tail--);
  18.         for (head = tail - 1; !arr[head] && head > 0; head--);
  19.         if (!arr[tail] && arr[head])
  20.         {
  21.             arr[tail] = arr[head];
  22.             arr[head] = 0;
  23.  
  24.             for (int i = 0; i < arrSize; i++) { cout << arr[i] << " ";} cout << endl;
  25.         }
  26.  
  27.     }
  28.  
  29.     for (int i = 0; i < arrSize; i++) { cout << arr[i] << " "; }    cout << endl;
  30. }
Add Comment
Please, Sign In to add comment