fork(2) download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. double res(int *arr, int len) {
  6. int min,max;
  7. min = arr[0];
  8. max = arr[0];
  9. for(int i = 1; i < len; i++) {
  10. if(arr[i] > max) {
  11. max = arr[i];
  12. }
  13. if(arr[i]<min) {
  14. min = arr[i];
  15. }
  16. }
  17. int sum = 0;
  18. int count = 0;
  19. for(int i = 0; i < len; i++) {
  20. if(arr[i] != max && arr[i] != min) {
  21. sum += arr[i];
  22. count++;
  23. }
  24. }
  25. return sum/((double)count);
  26.  
  27. }
  28.  
  29. int main() {
  30. int m, n;
  31. cin >> n >> m;
  32. cout << fixed << setprecision(2);
  33. for(int i = 0; i < m; i++) {
  34. int* arr = new int[n];
  35. for(int j = 0 ; j < n; j++) {
  36. cin >> arr[j];
  37. }
  38. cout << res(arr, n) << " ";
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 15232KB
stdin
5 4
7 8 9 8 10
6 5 5 4 7 
9 9 10 7 7
7 7 10 9 8
stdout
8.33 5.33 9.00 8.50