-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTricky Permutations.cpp
More file actions
58 lines (54 loc) · 1 KB
/
Tricky Permutations.cpp
File metadata and controls
58 lines (54 loc) · 1 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define re(i, n) for(int i = 0; i < n; i++)
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define ren(i,a,b) for(int i = (a); i >= (b); i--)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
std::vector<string> v(1000000);
int k = 0;
bool comp(string s1 , string s2)
{
if(s1 < s2)
return 1;
else
return 0;
}
void per(string s ,int ind)
{
if(ind == s.length()-1)
{
v[k] = s;
k++;
return ;
}
rep(i , ind , s.length()-1){
swap(s[ind] , s[i]);
per(s , ind+1);
swap(s[ind] , s[i]);
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
per(s , 0);
sort(v.begin() , v.begin()+k , comp);
cout << v[0] << "\n";
rep(i , 1 , k)
{
if(v[i] != v[i-1])
cout << v[i] <<"\n";
}
return 0;
}