天天看點

列印字元串所有字串

#include <iostream>
using namespace std;

int main(void)
{
	char a[] = "abcde";
	int len = strlen(a);
	unsigned int n = 0x1;
	
	for(int i = 1; i < len; ++i)
	{
		n |= (n << 1);
	}

	while(n)
	{
		unsigned int t = (1 << (len - 1));
		int i = 0, j = 0;
		char b[len];
		while(i < len)
		{
			if(n & t)
				b[j++] = a[i];
			i++;
			t >>= 1;
		}
		b[j] = '\0';
		puts(b);
		n--;
	}
	return 0;
}