-
Notifications
You must be signed in to change notification settings - Fork 0
/
1009B.cpp
64 lines (64 loc) · 1.34 KB
/
1009B.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
63
64
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
string s;
cin >> s;
int len = s.size();
int ok = 1;
inner :
// while(ok)
// {
// ok = 0;
for(int i= 0; i<len ; i++)
{
string sub = s.substr(i,2);
if(sub == "10")
{
swap(s[i],s[i+1]);
int j = i;
while(j)
{
if(s[j]=='0' && s[j-1]=='1') swap(s[j],s[j-1]);
else break;
j--;
}
}
else if(sub == "21")
{
swap(s[i],s[i+1]);
int j = i;
while(j)
{
if(s[j]=='1' && s[j-1]=='2') swap(s[j],s[j-1]);
else break;
j--;
}
}
else if(sub == "12")
{
swap(s[i],s[i+1]);
int j = i;
while(j)
{
if(s[j]=='1' && s[j-1]=='2') swap(s[j],s[j-1]);
else break;
j--;
}
}
else if(sub == "01")
{
swap(s[i],s[i+1]);
int j = i;
while(j)
{
if(s[j]=='1' && s[j-1]=='2') swap(s[j],s[j-1]);
else break;
j--;
}
}
}
// }
cout << s << endl;
}