2013校园招聘---暴风影音---笔试题--输入n,输出对应的所有长度为n的二进制串
输入1
输出:
0
1
输入3:
输出:
000
001
010
011
100
101
110
111
//暴风影音 2013 校园招聘 笔试题#include <iostream>#include <math.h>#include <stack>using namespace std;void print(unsigned int n){int max = pow((double)2,(int)n);unsigned int MASK = 0x00000001;stack<int> s;for(unsigned int i=0; i<max; i++){for(int j=0; j<n; j++){s.push(((i & MASK)==MASK) ? 1:0);MASK=MASK<<1;}while(s.size()){cout << s.top();s.pop();}MASK=MASK>>n;cout << endl;}}void main(){print(3);}