Skip to content

Instantly share code, notes, and snippets.

@avanishgiri
Created November 8, 2013 01:15
Show Gist options
  • Save avanishgiri/7364678 to your computer and use it in GitHub Desktop.
Save avanishgiri/7364678 to your computer and use it in GitHub Desktop.
combo.cpp
#include <iostream>
using namespace std;
void combos(string soFar, string rest, string full){
if(rest == ""){
int len = full.length();
for(int i = 0, j = 0; i < len; i++)
{
if(i == (int)(soFar[j] - '0')){
cout << (char)(full[i] - 32) << " ";
j++;
}
else
cout << full[i] << " ";
}
cout << endl;
}
else {
string current = rest.substr(0,1);
string remaining = rest.substr(1);
combos(soFar + current, remaining,full);
combos(soFar,remaining,full);
}
}
void print_combos(string s){
int len = s.length();
string str(len,' ');
for(int i = 0; i < len; i++)
str[i] = char(i+48);
combos("",str,s);
}
int main(){
print_combos("hello");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment