蓝桥杯基础练习:01字串
来源:互联网 发布:知乎修改名字 编辑:程序博客网 时间:2024/05/17 22:14
问题描述
对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011
00100
请按从小到大的顺序输出这32种01串。
输入格式
本试题没有输入。
输出格式
输出32行,按从小到大的顺序每行一个长度为5的01串。
样例输出
00000
00001
00010
00011
00001
00010
00011
#include<iostream> using namespace std; void printbinary(const unsigned int val) { for(int i = 4; i >= 0; i--) { if(val & (1 << i)) cout << "1"; else cout << "0"; } } int main(){/*for(int i=0;i<31;i++){printbinary(i);cout<<endl;}*/cout<<"00000"<<endl;cout<<"00001"<<endl;cout<<"00010"<<endl;cout<<"00011"<<endl;cout<<"00100"<<endl;cout<<"00101"<<endl;cout<<"00110"<<endl;cout<<"00111"<<endl;cout<<"01000"<<endl;cout<<"01001"<<endl;cout<<"01010"<<endl;cout<<"01011"<<endl;cout<<"01100"<<endl;cout<<"01101"<<endl;cout<<"01110"<<endl;cout<<"01111"<<endl;cout<<"10000"<<endl;cout<<"10001"<<endl;cout<<"10010"<<endl;cout<<"10011"<<endl;cout<<"10100"<<endl;cout<<"10101"<<endl;cout<<"10110"<<endl;cout<<"10111"<<endl;cout<<"11000"<<endl;cout<<"11001"<<endl;cout<<"11010"<<endl;cout<<"11011"<<endl;cout<<"11100"<<endl;cout<<"11101"<<endl;cout<<"11110"<<endl;cout<<"11111"<<endl;return 0;}
0 0
- 蓝桥杯:基础练习 01字串
- 蓝桥杯 【基础练习】 01字串
- “蓝桥杯”基础练习:01字串
- 蓝桥杯基础练习--01字串
- 蓝桥杯基础练习:01字串
- 蓝桥杯 基础练习 01字串
- 蓝桥杯--基础练习 01字串
- 蓝桥杯基础练习 01字串
- 蓝桥杯-基础练习-01字串
- 蓝桥杯 基础练习 01字串
- 蓝桥杯--基础练习--01字串
- 蓝桥杯基础练习 01字串
- 蓝桥杯-基础练习 01字串
- 蓝桥杯基础练习 01字串
- 蓝桥杯-基础练习 01字串
- 蓝桥杯基础练习 01字串
- 蓝桥杯 基础练习 01字串
- 蓝桥杯 基础练习 01字串
- C# 实现脚本辅助功能
- weka开发简介
- 安装vmare-tools——实现ubuntu与windows的互相复制与粘贴
- 解决resignFirstResponder或者endEditing无效的办法
- 在Java中使用正则表达式获取关键字
- 蓝桥杯基础练习:01字串
- 读取coco2dx下的resource的json文件
- weblogic与Java类加载器原理试验解析
- Java 读取Excel文件
- /var/log目录下的20个Linux日志文件功能详解
- 时间的遍历
- C#如何用换行符,Tab 作为split的分割符?
- AJAX的学习随记
- C++ 验证微软数字签名