Advertisement
audreych

12931 - Finding pairs - (2)

Jan 24th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. // basic counting way
  3. long long int cnt[10005];
  4. int main(){
  5.     int x;
  6.     int N;
  7.     long long int total = 0;
  8.     scanf("%d", &N);
  9.     for(int i = 0; i < N; i++){
  10.         // basically we just add the amount of pair we had b4, because position doesn't matter
  11.         // only amount of numbers matters
  12.         // 'streaming' algorithm
  13.         // replace x, we do not need to use another array
  14.         scanf("%d", &x);
  15.         total += cnt[x]++;
  16.     }
  17.     printf("%lld\n", total);
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement