用数字打印所有可能的组合
Print all of the possible combinations with numbers
所以,我的想法很简单:打印给定X个数字的所有可能的组合。。。
例如,我有两个数字,1和0,所以程序打印:
(0,0)
(0,1)
(1,0)
(1,1)
有没有用C、C++或Python实现这一点的想法?(如果你知道如何用其他语言做到这一点,请无论如何帮助我)。
谢谢。
使用itertools.product。使用以下示例并根据需要扩展
>>> [x for x in itertools.product("01",repeat=2)]
[('0', '0'), ('0', '1'), ('1', '0'), ('1', '1')]
>>>
相关文章:
- 有可能在Armadillo中复制MATLAB circshift方法吗
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 在他自己的方法中,有可能将一个对象取消引用到另一个对象吗
- 有可能使shared_ptr协变吗
- 有可能在信号处理程序中设置promise吗
- 是否有可能实现O(N)时间和O(1)空间解决方案,以实现C++中的字符串循环移位
- 是否有可能构建面向Linux和Windows的.Net Core C++ / CLI应用程序?
- 是否有可能使用debug_info获取ELF文件的源代码?
- C++,是否有可能/如何定义在.h和.cpp源文件中调用函数的类构造函数
- 有可能在C++中有类的查找表吗
- 是否有可能让 c++ dll 在后台运行 python 程序并让它填充向量图?如果是这样,如何?
- 向量的大小是否有可能为 1 但其中的元素数量为零?
- 是否有可能编写新的叮当声现代化规则?
- 是否有可能通过指向另一个未关联的子对象的指针来获取指向一个子对象的指针?
- 是否有可能通过演绎指南实现整个 std::make_tuple 功能?
- 是否有可能在没有复制的情况下传递 std::vector<int> 作为参数来获得 std::vector<std::array<int, 3>>?
- 如果我们从每个 Y 向量中选择一个值,则 X 数字的每个组合都可能
- 是否有可能具有放入容器的移动操作的类型?
- 是否有可能通过溢出 C 中的第一个元素来写入数组第二个元素
- 是否有可能组合对称的代码片段