fork download
  1. #include <iostream>
  2.  
  3. //наивный алгоритм сложностью O(n^2)
  4. int* unique_cpy(int* d, const int* f, const int* l){
  5. const int* p;
  6. for(; f != l; ++f){
  7. p = f + 1;
  8. while((p < l) && (*p != *f))
  9. ++p;
  10. if(p >= l)
  11. *d++ = *f;
  12. }
  13. return d;
  14. }
  15.  
  16.  
  17. int main(void){
  18. int A[10] = { 1, 2, 1, 3, 5, 3, 3, 4, 4, 3 };
  19. int B[10];
  20.  
  21. int* e = unique_cpy(B, A, A + sizeof(A)/sizeof(A[0]));
  22. for(int* p = &B[0]; p != e; ++p)
  23. std::cout << *p << ' ';
  24. return 0;
  25. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
2 1 5 4 3