-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (40 loc) · 764 Bytes
/
main.cpp
File metadata and controls
44 lines (40 loc) · 764 Bytes
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
#include <iostream>
#include <string>
#include <cstdio>
#include <string.h>
#include <set>
using namespace std;
void Swap(char *x,char *y)
{
swap(*x,*y);
}
void permute(char* b,char *a, int l, int r)
{
// char c=b;
int i;
if (l == r+1)
{
cout << a <<endl;
}
else
{
for (i = l; i <= r; i++)
{
Swap((a+l), (a+i));
permute(b,a , l+1, r);
Swap((a+l), (a+i));
permute(b,a , l+1, r);
Swap((a+l),b);
permute(b,a , l+1, r);
Swap(a+i,b); //backtrack
}
}}
int main()
{
char *b;
char str [100] ;
cin >> b >> str;
int n = strlen(str);
permute(b,str, 0, n-1);
return 0;
}