ProblemA: 01串

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

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

#include<bits/stdc++.h>
using namespace std;
int main(){

	for(int i=0;i<32;i++){
		int a[10]={0};
		int n=i;
		int count=0;
		while(n!=0){
			int temp=n%2;
			n=n/2;
			a[count++]=temp;
		}
		for(int i=4;i>=0;i--){   //倒叙
			cout<<a[i];
		}
		cout<<endl;
	} 
	
	return 0;
} 
发布了27 篇原创文章 · 获赞 1 · 访问量 1673

猜你喜欢

转载自blog.csdn.net/qq_37959151/article/details/102755649