fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int ile, a;
  9. cin >> ile;
  10. for (int b=0; b<ile; b++)
  11. {
  12. cin >> a;
  13. double n=0;
  14. int *tab=new int[a];
  15. for (int c=0; c<a; c++)
  16. {
  17. cin >> tab[c];
  18. n+=tab[c];
  19. }
  20. n=n/a;
  21. int naj=tab[0],pom=abs(tab[0]-n);
  22. for( int e=1; e<a; e++)
  23. {
  24. if( pom > abs(tab[e]-n))
  25. {
  26. pom=abs(tab[e]-n);
  27. naj=tab[e];
  28. }
  29. }
  30. cout << naj << endl;
  31. delete [] tab;
  32. }
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4912KB
stdin
4
4 2 3 0 4
4 1 2 3 4
4 4 3 2 1
4 0 2 3 4
stdout
2
2
3
2