input1 634 B

1234567891011121314151617181920212223242526272829
  1. #include "common.h"
  2. int uniquify(unsigned int *a, unsigned int n) {
  3. int i, j;
  4. if (n==0) return 0;
  5. for (i = 0, j = 1; j < n; j++) {
  6. if (a[j] < a[i])
  7. return -1; // array is not sorted in increasing order
  8. if (a[j] > a[i]) // a[j] is the next distinct integer
  9. a[++i] = a[j];
  10. }
  11. return i+1;
  12. }
  13. int main(int ac, char *av[])
  14. {
  15. unsigned int A[100];
  16. int num_distinct, i;
  17. for (i = 0; i < ac-1; i++)
  18. A[i] = atoi(av[i+1]);
  19. num_distinct = uniquify(A, i);
  20. for (i = 0; i < num_distinct; i++)
  21. printf("%d ", A[i]);
  22. putchar('\n');
  23. return 0;
  24. }