Advertisement
Axeer

pz3_2

Oct 19th, 2021
1,640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include <math.h>
  2. #include <iostream>
  3. #include <random>
  4. #include <chrono>
  5. #include <iomanip>
  6. #include <string>
  7.  
  8. std::random_device rd;
  9. std::mt19937::result_type seed = rd() ^ (
  10.     (std::mt19937::result_type)
  11.     std::chrono::duration_cast<std::chrono::seconds>(
  12.         std::chrono::system_clock::now().time_since_epoch()
  13.         ).count() +
  14.     (std::mt19937::result_type)
  15.     std::chrono::duration_cast<std::chrono::microseconds>(
  16.         std::chrono::high_resolution_clock::now().time_since_epoch()
  17.         ).count());
  18. std::mt19937 gen(seed);
  19.  
  20. __forceinline unsigned int randint(int min, int max) {
  21.     std::uniform_int_distribution<unsigned> distrib(min, max);
  22.     return distrib(gen);
  23. }
  24.  
  25. unsigned char max_nums;
  26.  
  27. decltype(max_nums) functia_huynctia() {
  28.     unsigned long long  min;
  29.     decltype(max_nums) result = 0;
  30.     max_nums |= (unsigned long long) - 1;
  31.     min |= (unsigned long long) - 1;
  32.  
  33.     std::pair<std::vector<int>, std::vector<int>> dva_celochislennych_massiva;
  34.  
  35.     for (int i = 0; i < max_nums; ++i) {
  36.         dva_celochislennych_massiva.first.push_back(randint(0, max_nums));
  37.         dva_celochislennych_massiva.second.push_back(randint(0, max_nums));
  38.     }
  39.     for (auto i : dva_celochislennych_massiva.first) {
  40.         i < min ? min = i : i = min;
  41.         std::vector<int>::iterator it = std::find(dva_celochislennych_massiva.second.begin(), dva_celochislennych_massiva.second.end(), min);
  42.         if (it >= dva_celochislennych_massiva.second.end())
  43.             min++;
  44.         else
  45.             result = dva_celochislennych_massiva.second[std::distance(dva_celochislennych_massiva.second.begin(), it)];
  46.     }
  47.     return result;
  48. }
  49.  
  50. int main()
  51. {
  52.     setlocale(LC_ALL, "RUS");
  53.  
  54.     std::wcout << L"Данная программа генерирует " << std::to_wstring(max_nums) << L" чисел" << std::endl;
  55.     for(int iter = 0; iter< 100; ++iter)
  56.         std::wcout << L"Минимальное значение из первой строки, не входящее во вторую: " << std::to_wstring(functia_huynctia()) << ", " << iter << L" итерации" << std::endl;
  57.     system("pause");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement