Advertisement
SmittenDreariness

WthoutLambdaProblem

Dec 5th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int reduce(long ar[], int n);
  5.  
  6. int main()
  7. {
  8.     long tab[] = {5, 3, 5, 6, 8, 2, 1, 3, 2, 8, 6, 1, 7};
  9.  
  10.     int size = reduce(tab, 13);
  11.  
  12.     std::cout << "size: " << size << std::endl;
  13.     std::cout << "tab: ";
  14.     std::for_each(tab, tab+size, [](const int& i){std::cout << i << " ";});
  15.  
  16.     return 0;
  17. }
  18.  
  19. int reduce(long ar[], int n)
  20. {
  21.     std::sort(ar, ar+n);
  22.     int size{};
  23.     long* end = std::unique(ar, ar+n);
  24.     for (long* it = ar; it != end; ++it)
  25.     {
  26.         ++size;
  27.     }
  28.     return size;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement