Created
November 8, 2013 08:27
-
-
Save avanishgiri/7367980 to your computer and use it in GitHub Desktop.
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 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