Advertisement
Josif_tepe

Untitled

Oct 28th, 2022
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.     int niza[n];
  12.     for(int i = 0; i < n; i++)
  13.     {
  14.         cin >> niza[i];
  15.     }
  16.     sort(niza, niza + n);
  17.     int sredisna_cifra = niza[n / 2];
  18.     int paricki = 0;
  19.     for(int i = 0; i < n; i++)
  20.     {
  21.         paricki += abs(sredisna_cifra - niza[i]);
  22.     }
  23.     cout << paricki << endl;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement