Created
November 8, 2013 01:15
-
-
Save avanishgiri/7364678 to your computer and use it in GitHub Desktop.
combo.cpp
This file contains hidden or 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 <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