问题描述时间限制:1.0s 内存限制:256.0MB
输入格式对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011
00100
请按从小到大的顺序输出这32种01串。
输出格式本试题没有输入。
样例输出输出32行,按从小到大的顺序每行一个长度为5的01串。
00000
00001
00010
00011
<以下部分省略>
代码
#include#include using namespace std; int main() { for (int i = 0; i <= 31; i ++ ) { int j = i; string res = ""; while (j) { if (j & 1) res = "1" + res; else res = "0" + res; j >>= 1; } for (int k = 0; k < 5 - res.length(); k ++ ) cout << "0"; cout << res << endl; } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)