我把复制uva中数据时,换行处复制过来变成了空格,自己改成换行就行了,最后提交可以AC的
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<cmath>
#include<string.h>
using namespace std;
int co[8][500];
int readchar()//读取一个不为换行、不为回车的字符
{
int c='\n';
while(c=='\n'||c=='\r')
{
c=getchar();
}
return c;
}
int readx(int x)//读取x个字符,并且计算他们的十进制数值
{
int sum=0;
while(x--)
{
sum=sum*2+readchar()-'0';//很巧妙,注意字符0的ascll码值不是0
}
return sum;
}
int readcode() //读取一行编码,假如读到了EOF,函数返回0,否则返回1
{
int c,x=1,y=0,counts=0;
memset(co,0,sizeof(co));//把数组初始化,这是一个好习惯,尽管这个题不需要这句话,其头文件为<string.h>
co[0][0]=readchar();//注意如果不是第一次读,那么缓冲区是有一个空格的,所以要么用
//readchar() 要么先用getchar()吃了缓冲区的空格,否则如果直接getchar()然后就会判定为
//编码输入结束了。。。就会全盘皆输
while(1)
{
c=getchar();
if(c==EOF)return 0;//输入流结束了
if(c=='\n'||c=='\r')break;
co[x][y]=c;
y++;
int b=(2<<x)-1;
if(y==b)
{
x++;
y=0;
}
}
return 1;
}
int main()
{
int a,code,b;
//freopen("input.txt","r",stdin);//输入重定向,方便测试代码,把测试数据放到文件 input.txt 中即可
while(readcode())
{
while(1)
{
a=readx(3);
if(a==0)break;
while(1)
{
b=readx(a);
if(b==((1<<a)-1))break;
putchar(co[a-1][b]);
}
}
putchar('\n');
}
/*readcode();//测试代码
for(int len=0;len<5;len++)
{
for(int i=0;i<(2<<len)-1;i++)
{
printf("code[%d][%d] = %c\n",len,i,co[len][i]);
}
}*/
return 0;
}
#include<stdlib.h>
#include<iostream>
#include<cmath>
#include<string.h>
using namespace std;
int co[8][500];
int readchar()//读取一个不为换行、不为回车的字符
{
int c='\n';
while(c=='\n'||c=='\r')
{
c=getchar();
}
return c;
}
int readx(int x)//读取x个字符,并且计算他们的十进制数值
{
int sum=0;
while(x--)
{
sum=sum*2+readchar()-'0';//很巧妙,注意字符0的ascll码值不是0
}
return sum;
}
int readcode() //读取一行编码,假如读到了EOF,函数返回0,否则返回1
{
int c,x=1,y=0,counts=0;
memset(co,0,sizeof(co));//把数组初始化,这是一个好习惯,尽管这个题不需要这句话,其头文件为<string.h>
co[0][0]=readchar();//注意如果不是第一次读,那么缓冲区是有一个空格的,所以要么用
//readchar() 要么先用getchar()吃了缓冲区的空格,否则如果直接getchar()然后就会判定为
//编码输入结束了。。。就会全盘皆输
while(1)
{
c=getchar();
if(c==EOF)return 0;//输入流结束了
if(c=='\n'||c=='\r')break;
co[x][y]=c;
y++;
int b=(2<<x)-1;
if(y==b)
{
x++;
y=0;
}
}
return 1;
}
int main()
{
int a,code,b;
//freopen("input.txt","r",stdin);//输入重定向,方便测试代码,把测试数据放到文件 input.txt 中即可
while(readcode())
{
while(1)
{
a=readx(3);
if(a==0)break;
while(1)
{
b=readx(a);
if(b==((1<<a)-1))break;
putchar(co[a-1][b]);
}
}
putchar('\n');
}
/*readcode();//测试代码
for(int len=0;len<5;len++)
{
for(int i=0;i<(2<<len)-1;i++)
{
printf("code[%d][%d] = %c\n",len,i,co[len][i]);
}
}*/
return 0;
}