对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:

来源:互联网 发布:淘宝助理5怎么上传图片 编辑:程序博客网 时间:2024/05/21 04:20
问题描述

对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:

00000

00001

00010

00011

00100

请按从小到大的顺序输出这32种01串。

输入格式
本试题没有输入。
输出格式
输出32行,按从小到大的顺序每行一个长度为5的01串。
样例输出
00000
00001
00010
00011
<以下部分省略>


#include <iostream>using namespace std;int main(){for(int i=0; i<32; ++i){int a[5] ={0};int temp = i;int index = 4;while (temp >= 1){a[index--] = temp % 2;temp = temp/2;}for (int idx = 0; idx < 5; ++idx){cout << a[idx];}cout << endl;}return 0;}



1 1
原创粉丝点击