fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a[1000], n, b, e, d = 0, f=-999999, c=99999;
  6. cin >> n;
  7. for(int i=0;i<n;i++){
  8. cin>>b;
  9. a[i] = b;
  10. }
  11. for(int i=0;i<n;i++){
  12. if(a[i] > f){
  13. f = a[i];
  14. }
  15. if(a[i] < c){
  16. c = a[i];
  17. }
  18. }
  19. for(int i=0;i<n;i++){
  20. if(a[i] == f){
  21. cout << c << " ";
  22. }
  23. else{
  24. cout << a[i] << " ";
  25. }
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5284KB
stdin
8
5 4 2 2 4 2 2 5
stdout
2 4 2 2 4 2 2 2