例题4-4 uva213

通过本题学习到了对于可能占好几行的输入,可以写一个自定义函数来过滤掉空格和回车。。还有就是二进制转化成十进制,,并且利用位运算来更快的判断边界条件。。二进制中要巧妙的运用位运算。
#include<stdio.h>
#include<string.h>
char code[10][1<<8];
char readchar()
{
	char ch=getchar();
	if(ch != '\n')
	return ch;
	else
	readchar();
}
int readcode()  //读取编码头 
{
	int len,i;
	memset(code,0,sizeof(code));
	for(len=1;len<8;len++)
	{
		for(i=0;i<(1<<len)-1;i++)
		{
			int ch=getchar();
			if(ch=='\n') return 1;
			if(ch==EOF) return 0;
			code[len][i]=ch;
		}
	}
}
int readint(int a)
{
	int v=0;
	while(a--)
	{
		v=v*2+readchar()-'0';
	}
	return v;
}
int main ()
{
	while (readcode())
	{
		for(;;)
		{
			int len=readint(3);
			if(len==0) break;
			for(;;)
			{
				int n=readint(len);
				if(n==(1<<len)-1) break;
				else putchar(code[len][n]);
			}
		}
		putchar('\n');
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值