d.c (483B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 /* Distinct */ 4 int 5 comp(const void *a, const void *b) 6 { 7 return *(int *)a - *(int *)b; 8 } 9 10 int 11 solution(int *A, int N) 12 { 13 int prev, res; 14 15 prev = 0; 16 res = 0; 17 18 qsort(A, N, sizeof(int), comp); 19 20 for (int i = 0; i < N; i++) { 21 if (i == 0) { 22 prev = A[i]; 23 res++; 24 } 25 else if (A[i] != prev) { 26 res++; 27 prev = A[i]; 28 } 29 } 30 31 return res; 32 } 33 34 int 35 main(void) 36 { 37 int a[] = {2, 1, 1, 2, 3, 1}; 38 39 printf("%d", solution(a, 6)); 40 41 return 0; 42 } 43