AquaBlitz11

TASK_051 - ChimengSoso's Solution

Jan 7th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int a[123];
  6. int cnt[1001];
  7.  
  8. int main() {
  9.     int n;
  10.     scanf("%d", &n);
  11.  
  12.     double avg = 0;
  13.     for (int i = 0; i < n; ++i){
  14.         scanf("%d", &a[i]);
  15.         avg += a[i];
  16.         ++cnt[a[i]];
  17.     }
  18.     avg /= n;
  19.  
  20.     sort(a, a+n);
  21.  
  22.     int n2d = (n-1)/2;
  23.     int n2u = n/2;
  24.     double med =  (a[n2d] + a[n2u]) / 2.0;
  25.  
  26.     int mode = 0;
  27.     for (int i = 0; i <= 1000; ++i) {
  28.         if (cnt[i] >= cnt[mode])
  29.             mode = i;
  30.     }
  31.  
  32.     printf("%.1lf\n", avg);
  33.     printf("%.1lf\n", med);
  34.     printf("%.1lf\n", (double)mode);
  35.  
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment