-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10597.cpp
53 lines (50 loc) · 899 Bytes
/
10597.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
#include <bits/stdc++.h>
#define swap(a,b) (a)^=(b)^=(a)^=(b)
#define endl '\n'
using namespace std;
typedef long long lld;
vector<int> v;
string s;
int kcnt;
bool check[55], flag;
void f(int pos, int k)
{
if(pos==kcnt)
{
flag = true;
return;
}
int oc = (int)(s[k]-'0'), tc = oc*10+(s[k+1]-'0');
if(!check[oc] && oc<=kcnt && oc>0)
{
check[oc] = true;
v.push_back(oc);
f(pos+1, k+1);
if(flag) return;
v.pop_back();
check[oc] = false;
}
if(!check[tc] && tc<=kcnt && tc>0)
{
check[tc] = true;
v.push_back(tc);
f(pos+1, k+2);
if(flag) return;
v.pop_back();
check[tc] = false;
}
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
cin>>s;
kcnt = s.length();
if(kcnt>9) kcnt = (kcnt-9)/2+9;
f(0, 0);
int size = v.size();
for(int i=0;i<size;i++)
cout<<v[i]<<' ';
return 0;
}