Advertisement
constk

MapPractice_Task1

Dec 15th, 2020
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <ctime>
  4. #include <iterator>
  5. #include <algorithm>
  6.  
  7. int main()
  8. {
  9.     using namespace std;
  10.  
  11.     srand(time(NULL));
  12.     int N = rand() * rand() % 100000; // Произвольно заданное число
  13.     cout << "N = " << N << endl;
  14.  
  15.     // Подготавливаем контейнер типа множество
  16.     set<int, less<int>> numbers;
  17.  
  18.     // Заполняем контейнер цифрами из числа N
  19.     while (N >= 1)
  20.     {
  21.         numbers.insert( N % 10 );
  22.         N /= 10;
  23.     }
  24.  
  25.     // Выводим цифры на экран
  26.     ostream_iterator<int> ositer(cout, " ");
  27.     cout << "There are digits: ";
  28.     copy(numbers.begin(), numbers.end(), ositer);
  29.  
  30.     system("pause>nul");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement