您的位置:首页 > 其它

UVa213-Message Decoding

2017-08-18 15:02 225 查看

UVa213-Message Decoding

思路:

紫书上的题目刚开始没有把各个功能独立开来能想到的例子都过了但是提交就RE,卡了巨长时间最后无奈按照书上思路把各个功能独立出来,一边过。无奈

代码:

#include <bits/stdc++.h>

using namespace std;
char ve[8][1<<9+1];
char getcha()
{
int ch;
while(ch=getchar())
{
if(ch!='\n'&&ch!='\t') return ch;
}
}
int getnum(int n)
{
int num=0;
while(n--) num=num*2+getcha()-'0';
return num;
}
int gethead()
{
char ch[100001];
int k=0;
memset(ve,0,sizeof(ve));
if(scanf("%[^\n]",ch)==-1) return 0;
for(int i=1;;i++)
{
for(int j=0;j<(1<<i)-1;j++,k++)
{
if(!ch[k]) return 1;
ve[i][j]=ch[k];
}
}
return 1;
}
int main()
{
int n;
while(gethead())
{
while(n=getnum(3),n)
{
int ans;
while(1)
{
ans=getnum(n);
if(ans==(1<<n)-1)break;
printf("%c",ve
[ans]);
}
}
printf("\n");
getchar();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: