fork download
  1. #include "iostream"
  2. #include "cmath"
  3.  
  4. using namespace std;
  5.  
  6. int ileLiczb, ileTestow, suma, cel, n;
  7. double srednia;
  8.  
  9.  
  10. int main()
  11. {
  12. cin >> ileTestow;
  13. if (ileTestow < 101)
  14. {
  15. for (int j = 0; j < ileTestow; j++)
  16. {
  17.  
  18. cin >> ileLiczb;
  19.  
  20. int *tablica = new int[ileLiczb];
  21.  
  22. for (int i = 0; i < ileLiczb; i++)
  23. {
  24. cin >> n;
  25. if (n > 0 && n < 100)
  26. {
  27. tablica[i] = n;
  28. suma += tablica[i];
  29. }
  30. else
  31. {
  32. i -= 1;
  33. }
  34. }
  35.  
  36. cel = tablica[0];
  37. srednia = suma / ileLiczb;
  38.  
  39. for (int i = 0; i < ileLiczb; i++)
  40. {
  41. if ((abs(srednia - tablica[i])) < ((abs(srednia - cel))))
  42. cel = tablica[i];
  43. }
  44.  
  45. cout << cel << endl;
  46. }
  47. }
  48. else
  49. {
  50. cout << "Max prob 100; " << endl;
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 4272KB
stdin
3
4 1 2 3 4 
4 4 3 2 1
4 0 3 2 4
stdout
2
4
4