fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<sstream>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<math.h>
  7.  
  8. using namespace std;
  9.  
  10. int main(){
  11. string line;
  12. int value, testy, srednia, a;
  13. int suma = 0;
  14. cin>>testy;
  15. cin.clear();
  16. cin.sync();
  17.  
  18. vector<vector<int> > liczby;
  19. vector<int> row;
  20.  
  21. for (int i=0; i<testy; i++){
  22. getline(cin, line);
  23. istringstream iss (line);
  24. while(iss >> value){
  25. row.push_back(value);
  26. }
  27. liczby.push_back(row);
  28. row.clear();
  29. }
  30.  
  31. for (int j=0; j<testy; j++){
  32. for (int k=1; k<(liczby[j][0]+1); k++){
  33. suma = suma + liczby[j][k];
  34. }
  35. srednia = suma / liczby[j][0];
  36. suma = 0;
  37. a = liczby[j][1];
  38. for (int l=1; l<(liczby[j][0]+1); l++){
  39. if (fabs(srednia-a) > fabs(srednia-liczby[j][l])){
  40. a = liczby[j][l];
  41. }
  42. }
  43. cout << a << endl;
  44. }
  45.  
  46. return 0;
  47. }
Runtime error #stdin #stdout 0s 15632KB
stdin
Standard input is empty
stdout
Standard output is empty