fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include<vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. vector<int>a;
  9. int el; //supporting variable for saving input values
  10. while(cin >> el)
  11. {
  12. a.push_back(el); //adding value to the vector
  13. }
  14. int min = a[0];
  15. int num = 0;
  16. double sum = 0;
  17. for(int i=0; i<a.size(); i++)
  18. {
  19. if(a[i]<=min) //finding the number of the minimal value
  20. {
  21. min = a[i];
  22. num = i;
  23. }
  24. sum += a[i];
  25. }
  26. int average = floor(sum/a.size()); //calculing the average of vector elements
  27. a[num] = average; //replacing minimal value by the average
  28. for(int i = 0; i < a.size(); i++)
  29. {
  30. cout << a[i] << " ";
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 3464KB
stdin
0 1 0 0 2 0 25
stdout
0 1 0 0 2 4 25