AquaBlitz11

TASK_051 - Poramee's Solution

Jan 7th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3.  
  4. int data[110];
  5. int modeChk[1010];
  6. int sum = 0;
  7.  
  8. int main() {
  9.     int n;
  10.     scanf("%d", &n);
  11.     int maxMode = -1;
  12.     for (int i = 1; i <= n; ++i) {
  13.         int input;
  14.         scanf("%d", &input);
  15.         sum += input;
  16.         data[i] = input;
  17.         ++modeChk[input];
  18.         if (modeChk[input] > maxMode) maxMode = modeChk[input];
  19.     }
  20.     double mean = 0, med = 0;
  21.     mean = (double)sum / n;
  22.     std::sort(data + 1, data + n + 1);
  23.     if ((n + 1) % 2 == 0) med = (double)data[(int)((n + 1) / 2)];
  24.     else {
  25.         double temp;
  26.         double sumT = 0;
  27.         temp = (double)(n + 1) / (double)2;
  28.         sumT += data[(int)(temp - 0.5)];
  29.         sumT += data[(int)(temp + 0.5)];
  30.         sumT /= (double)2;
  31.         med = sumT;
  32.     }
  33.  
  34.     printf("%.1lf\n%.1lf\n", mean, med);
  35.     int maxDataMode = -1;
  36.     for (int i = 1; i <= 1000; ++i) {
  37.         if (modeChk[i] == maxMode){
  38.             maxDataMode = i;
  39.         }
  40.     }
  41.     printf("%.1lf",(double)maxDataMode);
  42. }
Add Comment
Please, Sign In to add comment