蓝桥基础训练——字符串篇

基础练习 01串

问题描述

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

00000

00001

00010

00011

00100

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

输入格式

本试题没有输入。

输出格式

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

样例输出

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

考点:循环(使用五层循环)

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	for(int i=0; i<2; i++) 
		for(int j=0; j<2; j++) 
			for(int k=0; k<2; k++) 
				for(int s=0; s<2; s++) 
					for(int t=0; t<2; t++) 
						printf("%d%d%d%d%d\n",i,j,k,s,t);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39825375/article/details/84931779