fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int compare(const void *a, const void *b) {
  5. return (*(int *)a - *(int *)b);
  6. }
  7.  
  8. int main() {
  9. int numbers[20], n = 0, num;
  10. char input[10];
  11.  
  12. while (1) {
  13. scanf("%s", input);
  14.  
  15. if (input[0] == 's' && input[1] == 't' && input[2] == 'o' && input[3] == 'p' && input[4] == '\0') {
  16. break;
  17. }
  18.  
  19. num = atoi(input);
  20.  
  21. int is_duplicate = 0;
  22. for (int i = 0; i < n; i++) {
  23. if (numbers[i] == num) {
  24. is_duplicate = 1;
  25. break;
  26. }
  27. }
  28. if (!is_duplicate) {
  29. numbers[n++] = num;
  30. }
  31. }
  32. qsort(numbers, n, sizeof(int), compare);
  33.  
  34. for (int i = 0; i < n; i++) {
  35. printf("%d ", numbers[i]);
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5272KB
stdin
1 5 7 8 20 4 stop 100
stdout
1 4 5 7 8 20