Astral_Rider

Untitled

May 30th, 2023
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int n, i, maxi = (int)-1e9, mini = (int)1e9;
  6. double max, min, total, average, a[1000], juedui[1000], juedui_max = (int)-1e9;
  7.  
  8. int main()
  9. {
  10.  
  11.     scanf("%d", &n);
  12.     for (i = 0; i < n; i++)
  13.         scanf("%lf", &a[i]);
  14.  
  15.     max = (int)-1e9;
  16.     min = (int)1e9;
  17.     for (i = 0; i < n; i++)
  18.     {
  19.         if (a[i] > max)
  20.             max = a[i], maxi = i;
  21.         if (a[i] < min)
  22.             min = a[i], mini = i;
  23.         total += a[i];
  24.     }
  25.  
  26.     average = (total - max - min) / (n - 2);
  27.  
  28.     juedui_max = juedui[0];
  29.     for (i = 0; i < n; i++)
  30.     {
  31.         if (i != mini && i != maxi)
  32.         {
  33.             juedui[i] = a[i] - average;
  34.             if (juedui[i] > 0)
  35.                 juedui[i] = juedui[i];
  36.             if (juedui[i] < 0)
  37.                 juedui[i] = -juedui[i];
  38.         }
  39.     }
  40.  
  41.     for (i = 0; i < n; i++)
  42.         if (juedui[i] > juedui_max && i != mini && i != maxi)
  43.             juedui_max = juedui[i];
  44.  
  45.     printf("%.2lf %.2lf", average, juedui_max);
  46.  
  47.     system("Pause");
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment