Untitled
unknown
plain_text
2 years ago
819 B
8
Indexable
#include <bits/stdc++.h>
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
using namespace std;
typedef long long ll;
int main(){
string a;//cin >> a;
a = "9672354";
int k, len = a.size()-1;
for(int i= len ; i >= 1; i--){
k = i-1;
while(a[i] <= a[k]){
--k;
if(k==-1) break;
}
if(k != -1){
swap(a[k],a[i]);
break;
}
else k = -1;
}
if(k != -1){
char s[len-k];
for(int i = 0; i <= len-k-1; i++) s[i] = a[k+1+i];
sort(s,s+len-k);
for(int i = 0; i <= k; i++) cout << a[i];
for(char x : s) cout << x;
cout << endl;
}
else cout << -1 << endl;
cerr << "\nTime elapsed: " << TIME << " s.\n";
return 0;
}
Editor is loading...
Leave a Comment