forked from the-moonLight0/Hactober-fest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext greater number.cpp
55 lines (52 loc) · 970 Bytes
/
next greater number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
void init_code(){
fast_io;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
void solve()
{
string s;
cin>>s;
int n=s.length();
int temp=INT_MAX,flag=0,it;
int i=n-2;
for(;i>=0;i--)
{
for(int j=i+1;j<n;j++)
{
if(s[j]>s[i] && s[j]<temp)
{
temp=s[j];
it=j;
flag=1;
}
}
if(flag == 1)
{
swap(s[i],s[it]);
break;
}
}
sort(s.begin()+i+1,s.end());
cout<<s<<" ";
}
int main() {
init_code();
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}