Advertisement
SteelK

Untitled

Apr 17th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int *copy_mas_out(int *in_mas, unsigned int in_length, int min)
  8. {
  9.     int unsigned z = 0;
  10.     int *copy_mas = new int[in_length];
  11.  
  12.     for (unsigned int i = 0; i < in_length; i++)
  13.     {
  14.         if ((in_mas[i] - min) <= 2)
  15.         {
  16.             copy_mas[z] = in_mas[i];
  17.             z++;
  18.         }
  19.     }
  20.     return copy_mas;
  21. }
  22.  
  23. int min(int *in_mas, unsigned int in_length)
  24. {
  25.     int min = in_mas[0];
  26.     for (unsigned int i = 1; i < in_length; i++)
  27.     {
  28.         if (min > in_mas[i])
  29.             min = in_mas[i];
  30.     }
  31.     return min;
  32. }
  33.  
  34. bool test()
  35. {
  36.     int *mas = 0;
  37.  
  38.     bool a1 = 0;
  39.     bool a2 = 0;
  40.     bool a3 = 0;
  41.  
  42.     int mas1[] = { 1, 1, 1, 1, 1 }; // 1, 1, 1, 1, 1
  43.     mas = copy_mas_out(mas1, sizeof(mas1) / sizeof(int), min(mas1, sizeof(mas1) / sizeof(int)));
  44.     if ((mas[0] == 1) && (mas[1] == 1) && (mas[2] == 1) && (mas[3] == 1) && (mas[4] == 1))
  45.         a1 = 1;
  46.  
  47.     int mas2[] = { 20, 19, 18, 31, 28, 20, 19 }; //20 19 20 19
  48.     mas = copy_mas_out(mas2, sizeof(mas2) / sizeof(int), min(mas2, sizeof(mas2) / sizeof(int)));
  49.     if ((mas[0] == 20) && (mas[1] == 19) && (mas[2] == 18) && (mas[3] == 20) && (mas[4] == 19))
  50.         a2 = 1;
  51.  
  52.     int mas3[] = { 20, -9, 31, 0, 40 }; //-9
  53.     mas = copy_mas_out(mas3, sizeof(mas3) / 4, min(mas3, sizeof(mas3) / sizeof(int)));
  54.     if (mas[0] == -9)
  55.         a3 = 1;
  56.  
  57.     return (a1 == 1 && a2 == 1 && a3 == 1);
  58. }
  59.  
  60. int main()
  61. {
  62.     setlocale(0, "");
  63.  
  64.     if (test())
  65.         cout << "Программа работает..." << endl;
  66.     else
  67.         cout << "Программа не работает :(..." << endl;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement