您的位置:首页 > 其它

usaco--heritage

2012-11-27 14:54 253 查看
纯属蒙过去的。汗一个。。。。程序有bug..

ifstream fin("heritage.in");

ofstream fout("heritage.out");

char io[maxn],po[maxn];

struct node

{

char ch;

node *left,*night;

};

node *newnode()

{

node *u=new node;

u->left=u->night=null;

u->ch='9';

return u;

}

node *root;

void init()

{

fin>>io>>po;

root=newnode();

}

void build(node *root,int li,int ri,int lp,int rp)

{

if(li>ri||lp>rp)

{

//cout<<"cao!"<<endl;

return;

}

if(li==ri)

{

root->ch=io[li];

return;

}

char ch=po[lp];

int pos;

for(int i=li;i<=ri;i++)

if(ch==io[i])

{

root->ch=ch;

pos=i;

break;

}

node *temp=newnode();root->left=temp;

build(temp,li,pos-1,lp+1,lp+pos-li);

temp=newnode();root->night=temp;

build(temp,pos+1,ri,lp+pos-li+1,rp);

}

void out(node *root)

{

if(root==null)return;

out(root->left);

out(root->night);

if(root->ch!='9')

fout<<root->ch;

delete root;

}

void slove()

{

int len=strlen(io);

len--;

build(root,0,len,0,len);

out(root);

}

int main()

{

init();

slove();

fout<<endl;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: