Advertisement
Nayeemzaman

Jumpity Digits

Aug 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     string num;
  8.  
  9.     cin>>num;
  10.  
  11.     string temp = num;
  12.     int len= num.size();
  13.  
  14.     int c=0;
  15.     for(int i=len-1; i>=0; i--)
  16.     {
  17.         for(int j=i-1; j>=0; j--)
  18.         {
  19.  
  20.             if((num[i]-'0')<(num[j]-'0'))
  21.             {
  22.  
  23.                 swap(num[i],num[j]);
  24.                 c++;
  25.                 break;
  26.             }
  27.         }
  28.         if(c==1) break;
  29.     }
  30.     if(c==1 && (num[0]-'0')!=0)
  31.         cout<<num<<endl;
  32.     else
  33.         cout<<-1<<endl;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement