fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define yes cout<<"YES\n"
  4. #define no cout<<"NO\n"
  5.  
  6. using namespace std;
  7.  
  8. long long isbit(long long n,int x){
  9. if((n & (1ll << x)))return 1;
  10. else return 0;
  11. }
  12. ll lcm(ll a,ll b)
  13. {
  14. return a/__gcd(a,b)*b;
  15. }
  16.  
  17. const int N = 3e5 + 10 , mod = 1e9 + 7, inf = INT_MAX;
  18. const double PI = 3.14159265359;
  19.  
  20. void solve(){
  21. int n;
  22. cin >> n;
  23. int arr[n], mx = 0, ind = -1;
  24. for (int i = 0; i < n; i++){
  25. cin >> arr[i];
  26. if (mx < arr[i]){
  27. mx = arr[i];
  28. ind = i;
  29. }
  30. }
  31. if(mx == 1){
  32. arr[n - 1] = 2;
  33. }else {
  34. arr[ind] = 1;
  35. }
  36. sort(arr, arr + n);
  37. for (auto &a : arr) cout << a << ' ';
  38. }
  39. int main(){
  40. ios_base::sync_with_stdio(NULL);
  41. cin.tie(0);cout.tie(0);
  42. //freopen("A.in", "r", stdin);
  43. //freopen("output.txt", "w", stdout);
  44. int t = 1;
  45. //cin >> t;
  46. while (t--){
  47. solve();
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty