Advertisement
avr39ripe

cppTwoSmallOneBigCompared

Jul 12th, 2021
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. int main()
  5. {
  6.     const int arrSmallSize{ 5 };
  7.     const int arrBigSize{ arrSmallSize * 2 };
  8.  
  9.     enum Conditions {greater, equal, less, maxConditions};
  10.  
  11.     int arrSmallA[arrSmallSize]{1,-4,-5,0,2};
  12.     int arrSmallB[arrSmallSize]{-5,0,7,4,-1};
  13.     int arrBig[arrBigSize]{}; //1 7 2 4 0 0 -5 -4 -5 -1
  14.     int bigIdx{ 0 };
  15.  
  16.  
  17.     for (int i{ 0 }; i < arrSmallSize; ++i) { std::cout << arrSmallA[i] << '\t'; } std::cout << '\n';
  18.     for (int i{ 0 }; i < arrSmallSize; ++i) { std::cout << arrSmallB[i] << '\t'; } std::cout << '\n';
  19.  
  20.     //for (int smallIdx{ 0 }; smallIdx < arrSmallSize; ++smallIdx)
  21.     //{
  22.     //  if (arrSmallA[smallIdx] > 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  23.     //  if (arrSmallB[smallIdx] > 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  24.     //}
  25.  
  26.     //for (int smallIdx{ 0 }; smallIdx < arrSmallSize; ++smallIdx)
  27.     //{
  28.     //  if (arrSmallA[smallIdx] == 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  29.     //  if (arrSmallB[smallIdx] == 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  30.     //}
  31.  
  32.     //for (int smallIdx{ 0 }; smallIdx < arrSmallSize; ++smallIdx)
  33.     //{
  34.     //  if (arrSmallA[smallIdx] < 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  35.     //  if (arrSmallB[smallIdx] < 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  36.     //}
  37.  
  38.  
  39.     for (int condition{ 0 }; condition < Conditions::maxConditions; ++condition)
  40.     {
  41.         for (int smallIdx{ 0 }; smallIdx < arrSmallSize; ++smallIdx)
  42.         {
  43.             if (condition == Conditions::greater)
  44.             {
  45.                 if (arrSmallA[smallIdx] > 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  46.                 if (arrSmallB[smallIdx] > 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  47.             }
  48.             else if (condition == Conditions::equal)
  49.             {
  50.                 if (arrSmallA[smallIdx] == 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  51.                 if (arrSmallB[smallIdx] == 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  52.             }
  53.             else if (condition == Conditions::less)
  54.             {
  55.                 if (arrSmallA[smallIdx] < 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  56.                 if (arrSmallB[smallIdx] < 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  57.             }
  58.         }
  59.     }
  60.  
  61.  
  62.     for (int bigIdx{ 0 }; bigIdx < arrBigSize; ++bigIdx) { std::cout << arrBig[bigIdx] << '\t'; } std::cout << '\n';
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement