清澄OJ 1001: 01序列

问题描述
  对于长度为6位的一个01串,每一位都可能是0或1,一共有64种可能。它的前几个是:
  000000
  000001
  000010
  000011
  000100
  请按从小到大的顺序输出这64种01串。
输出格式
  输出64行,每行一个01串。

问题分析

这是一个循环打印0和1的题目,对比了几种方法,觉得境界不同。

亲,你达到那种境界了呢?


源代码1 (憨厚的做法)

#include<stdio.h>
#include<stdlib.h>

int main()
{ 
	char c1[]="000000\n000001\n000010\n000011\n000100\n000101\n000110\n000111\n";
	char c2[]="001000\n001001\n001010\n001011\n001100\n001101\n001110\n001111\n"; 
	char c3[]="010000\n010001\n010010\n010011\n010100\n010101\n010110\n010111\n"; 
	char c4[]="011000\n011001\n011010\n011011\n011100\n011101\n011110\n011111\n"; 
	char c5[]="100000\n100001\n100010\n100011\n100100\n100101\n100110\n100111\n"; 
	char c6[]="101000\n101001\n101010\n101011\n101100\n101101\n101110\n101111\n"; 
	char c7[]="110000\n110001\n110010\n110011\n110100\n110101\n110110\n110111\n"; 
	char c8[]="111000\n111001\n111010\n111011\n111100\n111101\n111110\n111111\n"; 
	printf("%s",c1); 
	printf("%s",c2); 
	printf("%s",c3); 
	printf("%s",c4); 
	printf("%s",c5); 
	printf("%s",c6); 
	printf("%s",c7); 
	printf("%s",c8);
	//system("pause");
	return 0;
}



源代码2 (屌丝的做法)

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b, c, d, e, f;
    for(a=0; a<=1; a++)
        for(b=0; b<=1; b++)
            for(c=0; c<=1; c++)
                for(d=0; d<=1; d++)
                    for(e=0; e<=1; e++)
                        for(f=0; f<=1; f++)
                            printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);
    //system("pause");
    return 0;
}

源代码3 (高富帅做法)

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a = 0;
 	char b[6];
  	while (a != 64)
  	{
    		itoa(a, b, 2);
    		printf("%06s\n", b);
    		a++;
  	}
	//system("pause");
	return 0;
}

源代码4 (我的做法)

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, j;
	for(i = 0; i < 64; i++)
	{
		for(j = 5; j >= 0; j--)
			printf("%d", (i >> j) & 1);
		printf("\n");
	}
	//system("pause");
	return 0;
}











  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值