蓝桥杯基础练习:01字串
2015-01-07 15:27
183 查看
问题描述
对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011
00100
请按从小到大的顺序输出这32种01串。
输入格式
本试题没有输入。
输出格式
输出32行,按从小到大的顺序每行一个长度为5的01串。
样例输出
00000
00001
00010
00011
对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011
00100
请按从小到大的顺序输出这32种01串。
输入格式
本试题没有输入。
输出格式
输出32行,按从小到大的顺序每行一个长度为5的01串。
样例输出
00000
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; }
相关文章推荐
- 蓝桥杯-基础练习之01字串——BASIC-2
- 蓝桥杯:基础练习 01字串【JAVA算法实现】
- 蓝桥杯(Java) 基础练习 01子串
- 蓝桥杯-01字串(基础练习)
- 【蓝桥杯练习系统】 基础练习 01字串
- 蓝桥杯:基础练习 数列特征、字母图形、01字串、闰年判断
- 蓝桥杯 BASIC_01 基础练习 闰年判断
- 蓝桥杯 基础练习 01字串(水题)
- 蓝桥杯 【基础练习】 01字串
- 蓝桥杯 基础练习 01字串 【暴力解决】
- 蓝桥杯 基础练习 01字串 简单解法
- 蓝桥杯练习:基础练习 01字串
- 蓝桥杯 BASIC_02 基础练习 01字串
- “蓝桥杯”基础练习:01字串
- 蓝桥杯--基础练习 01字串
- 蓝桥杯OJ刷题日记——01-基础练习 闰年判断
- 蓝桥杯OJ刷题日记——02-基础练习 01字串
- 蓝桥杯练习系统基础练习——01字符串
- 蓝桥杯--基础练习--01字串
- 【蓝桥杯】【基础练习12】【01字串】