已知一个由0,1字符组成的长度为2^n的字符串。请按以下规则将已给出的字符串分解为FBZ串:
(1)若其中字符全为'1',则称之为"B"串;
(2)若其中字符全为'0',则称之为"Z"串;
(3)若不全为‘0’,同时也不全为'1',则称“F”串;若此串为F串,则应将此串分解为2个长度为2^(n-1)的子串。
对分解后的子串,仍按以上规则继续分解,直到全部为B串或为Z串为止。
例如n=3时,给出0-1串为: 10111001,由下图可知,最后的输出应该是FFFBZBFFBZFZB
#include<bits/stdc++.h>
using namespace std;
const int n=8;
int i,j,st11=1,st12=1,st2,s,t;
char str1[n*2+1][n+1],str2[44];
int main()
{
for(i=1;i<=n*2;i++)
for(j=1;j<=n;j++) str1[i][j]=' ';
for(i=1;i<=n;i++) str1[1][i]=getchar();
while(_____(1)______)
{
s=t=0;
for(i=1;i<=n;i++)
{
if(str1[st12][i]=='1') s++;
if(str1[st12][i]=='0') t++;
}
if(____(2)_____) st2++,str2[st2]='B';
else if(_____(3)______) st2++,str2[st2]='Z';
else
{
st2++,str2[st2]='F',j=(s+t)/2;
for(s=n*2-2;s>=_____(4)______;s--)
for(t=1;t<=n;t++) str1[s+2][t]=str1[s][t];
st11+=2;
for(i=1;i<=j;i++)
{
str1[st12+1][i]=str1[st12][i];
str1[st12+2][i]=_____(5)_____;
}
for(i=_____(6)_____;i<=n;i++)
str1[st12+1][i]=' ',str1[st12+2][i]=' ';
}
st12++;
}
for(i=1;i<=st2;i++) printf("%c",str2[i]);
return 0;
}