fork(1) download
  1. #include <iostream>
  2.  
  3. int* array_remove(int* f, int* l, bool (*cmp)(int)){
  4. while((f != l) && ! (*cmp)(*f))
  5. ++f;
  6. for(int* p = f; p != l; *p = *f){
  7. if((*cmp)(*f))
  8. --l;
  9. else
  10. ++p;
  11. ++f;
  12. }
  13. return l;
  14. }
  15.  
  16. bool compare(int n){
  17. int k = n % 10;
  18. for(n /= 10; n != 0; n /= 10){
  19. if((n % 10) != k)
  20. return false;
  21. }
  22. return true;
  23. }
  24.  
  25.  
  26. int main(void) {
  27. int a[] = {1, 2000, 3, 4444, 5, 66, 717, 82, 9};
  28. size_t n = sizeof(a)/sizeof(a[0]);
  29.  
  30. const int* e = array_remove(a, a + n, &compare);
  31. for(const int* p = &a[0]; p != e; ++p)
  32. std::cout << *p << ' ';
  33. std::cout << std::endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
2000 717 82