A1002. 01序列2
时间限制:
1.0s 内存限制:
256.0MB
问题描述
对于长度为6位的一个01串,每一位都可能是0或1,一共有64种可能。它的前几个是:
000000
000001
000010
000011
000100
有这些01串中,有一些01串的1的个数是奇数个,这部分01串的前几个是:
000001
000010
000100
000111
001000
001011
请按从小到大的顺序输出这些01串。
000000
000001
000010
000011
000100
有这些01串中,有一些01串的1的个数是奇数个,这部分01串的前几个是:
000001
000010
000100
000111
001000
001011
请按从小到大的顺序输出这些01串。
输出格式
每行一个01串。
- #include <stdio.h>
- //#include <iostream>
- #include <stdlib.h>
- int main(){
- int i=0,j=0,x;
- int count=0;
- char temp[6];
- while(i!=64)
- {
- itoa(i,temp,2);
- for(j=0;j<6;j++)
- if(temp[j]=='1')
- count++;
- if(count%2==1)
- printf("%06s\n",temp);
- count=0;
- i++;
- //x=atoi(temp);
- //printf("%06d\n",x);
- }
- getchar();
- return 0;
- }