-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprintPermutations.cpp
More file actions
44 lines (36 loc) · 813 Bytes
/
Copy pathprintPermutations.cpp
File metadata and controls
44 lines (36 loc) · 813 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
// https://youtu.be/K5xJXbnYMBc?list=PL-Jc9J83PIiFj7YSPl2ulcpwy-mwj1SSk
//Solution :
#include<vector>
#include<string>
#include<iostream>
using namespace std;
void permutations(string s,vector<bool> visited,vector<string> &v,string temp)
{
if(temp.length()==s.length())
{
v.push_back(temp);
}
else
{
for(int i=0;i<s.length();i++)
{
if(!visited[i])
{
visited[i]=true;
permutations(s,visited,v,temp+s[i]);
visited[i]=false;
}
}
}
}
int main()
{
string s;
cin>>s;
vector<string> v;
vector<bool> visited(s.length(),false);
permutations(s,visited,v,"");
cout<<"PERMUTATIONS OF "<<s<<" are : \n\n";
for(auto &words:v)
cout<<words<<"\n";
}