Advertisement
silentkiler029

Distinct numbers in an array (with negative numbers)

Jun 11th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. /*  BISMILLAHIR-RAHMANIR-RAHIM
  2.  ____________________________________
  3. |                                    |
  4. |       SHANTO_SUST_SWE-19_029       |
  5. |____________________________________|
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13.  
  14. #define debug 1
  15.  
  16. int number[2000005];
  17.  
  18. int main()
  19. {
  20.     int n;
  21.     scanf("%d", &n);
  22.     int ara[n];
  23.     int i, max = -1000005;
  24.  
  25.     for(i = 0; i < n; i++){
  26.         scanf("%d", &ara[i]);
  27.         number[ara[i] + 1000001]++;
  28.         if(ara[i] > max){
  29.             max = ara[i];
  30.         }
  31.     }
  32.  
  33.     int count = 0;
  34.  
  35.     for(i = 0; i <= 1000001 + max; i++){
  36.         if(number[i] > 0){
  37.             count++;
  38.         }
  39.     }
  40.  
  41.     printf("%d\n", count);
  42.  
  43.  
  44.     return 0;
  45. }
  46.  
  47. //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement