fork(6) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double naj;
  7.  
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. int t;
  14. int n;
  15. cin>>t; //ile testow
  16. cin>>n; //ile liczb
  17.  
  18. int liczby[10000];
  19.  
  20. for(int i=1;i<=t;i++)
  21. {
  22. double suma=0;
  23. for(int i=1; i<=n;i++)
  24. {
  25. cin>>liczby[i];
  26. suma+=liczby[i];
  27. }
  28. suma/=n;
  29. naj=liczby[0];
  30. for(int i=1;i<=n;i++)
  31. {
  32. if(abs(suma-liczby[i])<(suma-naj))
  33. naj=liczby[i];
  34. }
  35. cout<<naj<<endl;
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 3472KB
stdin
3
4 1 2 3 4 
4 4 3 2 1
4 0 3 2 4

Output:
2
3
2
stdout
2
4
1