Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- string num;
- cin>>num;
- string temp = num;
- int len= num.size();
- int c=0;
- for(int i=len-1; i>=0; i--)
- {
- for(int j=i-1; j>=0; j--)
- {
- if((num[i]-'0')<(num[j]-'0'))
- {
- swap(num[i],num[j]);
- c++;
- break;
- }
- }
- if(c==1) break;
- }
- if(c==1 && (num[0]-'0')!=0)
- cout<<num<<endl;
- else
- cout<<-1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement