-
Notifications
You must be signed in to change notification settings - Fork 5
/
a.cpp
62 lines (52 loc) · 968 Bytes
/
a.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
56
57
58
59
60
61
62
#include<iostream>
using namespace std;
int main()
{
int a=12453;
int temp= a;
int count=0;
while(temp!=0)
{
temp=temp/10;
count++;
}
int d[count];
temp=a;
for(int i=0; i<=count-1; i++)
{
d[i]=temp%10;
temp=temp/10;
}
int k=-1;
for(int i=1; i<=count-1; i++)
{
if(d[i] < d[i-1])
{
k=i;
break;
}
}
if(k==-1)
{
cout<<"NOtpossible"<<endl;
}
else{
for(int i=0; i<=k-1; i++)
{
for(int j=0; j<=k-1-i; j++)
{
if(d[j]<=d[j+1])
continue;
temp=d[j]; //swapping a[j] and a[j+1]
d[j] = d[j+1];
d[j+1] =temp;
}
}
}
for(int i=count-1; i>=0; i--)
{
cout<<d[i];
}
// cout<<count<<endl;
return 0;
}