I am trying to find the subsets and output them with binary representation.
EXAMPLE:
000:EMPTY 001:C 010:B 011:B C 100:A 101:A C 110:A B 111:A B C
I have the following code that finds all subsets but not sure about the binary??
#include <iostream>
using namespace std;
enter code here
void recsub(string sofar, string rest){
if(rest=="") cout<<sofar<<endl;
else{
recsub(sofar+rest[0], rest.substr(1)); //including first letter
recsub(sofar, rest.substr(1)); //recursion without including first letter.
}
}
void listsub(string str){
recsub("",str);
}
int main(){
listsub("abc");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire