Advertisement
bigdaddytsotne

16//

Dec 6th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <vector>
  2. #include <random>
  3. #include <ctime>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. bool isEqualTo12(int a)
  10. {
  11.     if (a < 10 || a > 99)
  12.         return false;
  13.  
  14.     int part1 = a / 10;
  15.     int part2 = a % 10;
  16.  
  17.     if ((part1 * part2) == 12)
  18.         return true;
  19.     else
  20.         return false;
  21. }
  22.  
  23. void task16()
  24. {
  25.     vector<int> vec1;
  26.  
  27.     default_random_engine dre(time(NULL));
  28.     uniform_int_distribution<int> rand(11, 99);
  29.  
  30.     for (size_t i = 0; i < 101; i++)
  31.     {
  32.         vec1.push_back(rand(dre));
  33.     }
  34.  
  35.  
  36.     int res = count_if(vec1.begin(), vec1.end(), isEqualTo12);
  37.  
  38.     int res1 = count_if(vec1.begin(), vec1.end(), [](int i) {return (i % 10) * (i / 10) == 12; });
  39.  
  40.  
  41.     cout << "Result: " << res;
  42.     cout << "Result1: " << res1;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement