You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
578 B

#include <bits/stdc++.h>
using namespace std;
int a[4] = {1, 3, 2, 4};
int main() {
// 步骤总结:二进制的模拟一般分为两层循环
// ① 枚举从1到 2^n-1,模拟每个可能出现的二进制状态对应的整数值
for (int i = 1; i < 1 << 4; i++) {
// ② 在对应的整数值确定后,枚举此数值的每一个数位
for (int j = 0; j < 4; j++)
// ③判断当前数位是不是1,是1表示当前数位选中
if (i >> j & 1) printf("%d ", a[j]);
puts("");
}
return 0;
}