Created
September 5, 2019 13:28
-
-
Save 08vivek08/c37e6ee85dbd7cac5fc822784e443a68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
set<vector<string>>s; | |
void distinct(string arr[],int n){ | |
vector<string>v; | |
for(int i=0;i<n;i++){ | |
v.push_back(arr[i]); | |
} | |
s.insert(v); | |
} | |
void permute(string arr[],int order,int n){ | |
if(order==n-1){ | |
distinct(arr,n); | |
return; | |
} | |
else{ | |
for(int i=order;i<n;i++){ | |
swap(arr[i],arr[order]); | |
permute(arr,order+1,n); | |
swap(arr[i],arr[order]); | |
} | |
} | |
} | |
int main(){ | |
int n; | |
cin>>n; | |
string arr[n]; | |
for(int i=0;i<n;i++){ | |
cin>>arr[i]; | |
} | |
sort(arr,arr+n); | |
permute(arr,0,n); | |
for(auto it=s.begin();it!=s.end();it++){ | |
vector<string>v=*it; | |
for(auto i=v.begin();i!=v.end();i++){ | |
cout<<*i<<" "; | |
} | |
cout<<"\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment