01字串-蓝桥杯

01字串

题目描述

  对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是
00000
00001
00010
00011
00100
  请按从小到大的顺序输出这32种01串。

输入

输出

  输出32行,按从小到大的顺序每行一个长度为5的01串。

样例输出

00000
00001
00010
00011
<以下部分省略>

来源/分类

  蓝桥杯

  打表或者二级制操作

#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#ifndef NULL
#define NULL 0
#endif
using namespace std;
 
int main()
{
    for (int i = 0; i <= 31; i++){
        for (int j = 4; j >= 0; j--)
            cout << ((i >> j)&1);
    cout << endl;
    }
    return 0;
}

或者

#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#ifndef NULL
#define NULL 0
#endif
using namespace std;
 
int main()
{
    printf("00000\n00001\n00010\n00011\n00100\n00101\n00110\n00111\n01000\n01001\n01010\n01011\n01100\n");
    printf("01101\n01110\n01111\n10000\n10001\n10010\n10011\n10100\n10101\n10110\n10111\n11000\n11001\n11010\n11011\n11100\n11101\n11110\n11111\n");
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值