fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. unsigned int n;
  7. int min, max;
  8.  
  9.  
  10. cin >> n;
  11.  
  12. vector <int> ar(n);
  13.  
  14. for (int i = 0; i < n; i++) {
  15. int temp;
  16. cin >> temp;
  17.  
  18. if (i == 0) {
  19. min = temp; max = temp;
  20. } else {
  21. if (temp < min) {
  22. min = temp;
  23. }
  24.  
  25. if (temp > max) {
  26. max = temp;
  27. }
  28. }
  29.  
  30. ar[i] = temp;
  31. }
  32.  
  33. for (int i = 0; i < n; i++) {
  34. if (ar[i] == max) {cout << min << " "; continue;}
  35. cout << ar[i] << " ";
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5320KB
stdin
8
5 4 2 2 4 2 2 5
stdout
2 4 2 2 4 2 2 2