fork(1) download
  1. using System;
  2. public class Program
  3. {
  4. static void Main(string[] args)
  5. {
  6. int t = int.Parse(Console.ReadLine());
  7. for (int i = 0; i < t; i++)
  8. {
  9. int n = 0;
  10. int liczba = 0;
  11. string nN = "";
  12. double min, srednia;
  13. int[] tab = new int[100];
  14. int suma = 0;
  15. nN = Console.ReadLine();
  16. string[] nTbl = nN.Split(' ');
  17. n = int.Parse(nTbl[0]);
  18. for (int j = 0; j < n; j++)
  19. {
  20. tab[j] = int.Parse(nTbl[j]);
  21. suma += tab[j];
  22. }
  23. srednia = ((double)(suma)) / n;
  24. min = 100;
  25. for (int j = 0; j < n; j++)
  26. {
  27. if (Math.Abs(tab[j] - srednia) < min)
  28. {
  29. min = Math.Abs(tab[j] - srednia);
  30. liczba = tab[j];
  31. }
  32. }
  33. Console.WriteLine(liczba);
  34. }
  35. }
  36. }
  37.  
  38.  
Success #stdin #stdout 0.04s 22928KB
stdin
3
4 1 2 3 4 
4 4 3 2 1
4 0 3 2 4
stdout
2
3
2