01序列2

来源:互联网 发布:办公自动化软件 编辑:程序博客网 时间:2024/04/30 02:48
问题描述
  对于长度为6位的一个01串,每一位都可能是0或1,一共有64种可能。它的前几个是:
  000000
  000001
  000010
  000011
  000100
  有这些01串中,有一些01串的1的个数是奇数个,这部分01串的前几个是:
  000001
  000010
  000100
  000111
  001000
  001011
  请按从小到大的顺序输出这些01串。
输出格式
  每行一个01串。



源代码

  1. #include<iostream>
  2. #include<bitset>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i,j;
  7.     for (i = 0; i < 64; i++)
  8.     {
  9.         j = int(bitset<6>(i).count());
  10.         if (j % 2 != 0)
  11.             cout << bitset<6>(i) << endl;
  12.     }
  13.     return 0;
  14. }

    0 0
    原创粉丝点击