-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathordering_subsets.cpp
More file actions
41 lines (36 loc) · 883 Bytes
/
Copy pathordering_subsets.cpp
File metadata and controls
41 lines (36 loc) · 883 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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool compare(string a ,string b){
if(a.length()==b.length()){
return a<b; //lexicographic order
}
return a.length()<b.length();
}
void finding_subsets(char *input,char *output, int i , int j, vector<string> &list){
//base case
if(input[i] =='\0'){
output[j] = '\0';
string temp(output);
list.push_back(temp);
return;
}
//recursive case
output[j]= input[i];
finding_subsets(input,output,i+1,j+1,list);
finding_subsets(input,output,i+1,j,list);
}
int main(){
char input[100];
char output[100];
vector<string> list;
cin>>input;
finding_subsets(input,output,0,0,list);
sort(list.begin(),list.end(),compare);
//print the output
for(auto s:list){
cout<<s<<"," ;
}
return 0;
}