UVa-213 Message Decoding
难题!又是借鉴了rujia的代码。看了好几遍,凭记忆和理解手打的居然一次AC。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char code[8][1<<8];
bool readcode()
{
memset(code,0,sizeof(code));
for(int i=1;i<=7;i++)
for(int j=0;j<(1<<i)-1;j++)
{
char ch=getchar();
if(ch==EOF) return 0;
if(ch=='\n') return 1;
code[i][j]=ch;
}
}
int readchar()
{
char ch;
while((ch=getchar())=='\n'){}
return ch-'0';
}
int readint(int n)
{
int a=0;
while(n--)
a+=readchar()*(1<<n);
return a;
}
int main()
{
//freopen("in.txt","r",stdin);
while(readcode())
{
while(1)
{
int len=readint(3);
if(len==0) break;
while(1)
{
int p=readint(len);
if(p==(1<<len)-1) break;
cout<<code[len][p];
}
}
getchar();
cout<<endl;
}
}