Advertisement
ekzolot

Untitled

Apr 15th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main(){
  6.     int n;
  7.     cin>>n;
  8.     vector <int> a(n);
  9.     for (int i=0; i<n; i++){
  10.         cin>>a[i];
  11.     }
  12.     bool b=0;
  13.     for (int i=0; i<n; i++){
  14.         if (a[i]!=a[0]){
  15.             b=1;
  16.         }
  17.     }
  18.     if (b==0){
  19.         cout<<"NO"<<endl;
  20.         return 0;
  21.     }
  22.     sort(a.begin(), a.end());
  23.     for (int i=n-1; i>0; i--){
  24.         if (a[i]!=a[i-1]){
  25.             swap(a[i], a[i-1]);
  26.             break;
  27.         }
  28.     }
  29.     for (int i=0; i<n; i++){
  30.         cout<<a[i];
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement