Skip to content

Instantly share code, notes, and snippets.

@avanishgiri
Created November 8, 2013 08:27
Show Gist options
  • Save avanishgiri/7367980 to your computer and use it in GitHub Desktop.
Save avanishgiri/7367980 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void print_combos(string s){
int len = s.length();
int iterations = 1 << len; //this makes iterations 2 to the power of length
for(int i = 0; i < iterations; i++){
for(int j = 0; j < len; j++){
if( i & (1 << j) ) // bitwise & operation and bitwise shift operation
cout << char( s[j] -32 ) << " "; // character - 32 makes capitalizes it
else
cout << s[j] << " ";
}
cout << endl;
}
}
int main(){
print_combos("hello");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment