fork(3) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10. int t;
  11. int ile;
  12. cin>>t;
  13. for(int i=0; i<t; i++) {
  14. cin>>ile;
  15. unsigned int *a = new unsigned int [ile];
  16. unsigned int *b = new unsigned int [ile];
  17. double c=0.0;
  18. double srednia=0.0;
  19. for(int i=0; i<ile; i++) {
  20. cin>>a[i];
  21. c+=a[i];
  22.  
  23. }
  24. if(c == 0 ) srednia = 0;
  25. else srednia = c / ile;
  26.  
  27. for(int i=0; i<ile; i++) {
  28.  
  29. b[i] = abs(srednia - a[i]);
  30. }
  31.  
  32. unsigned int m = 4294967295;
  33. double wynik;
  34. if(srednia == 0) wynik = 0;
  35. else {
  36. for(int i=0; i<ile; i++) {
  37. if(b[i] < m) {
  38. m = b[i];
  39. wynik = a[i];
  40. }
  41. }
  42. }
  43. cout << wynik << endl;
  44.  
  45. delete [] a;
  46. delete [] b;
  47.  
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty