1 #include <iostream>
2 #include <string>
3 using namespace std;
4 struct TreeNode
5 {
6 char a;
7 TreeNode *lchild,*rchild;
8 };
9 bool build(TreeNode *&root,string s,int &n)
10 {
11 char c=s[n];
12 if(n>s.length()-1) return false;
13 n++;
14 if(c==‘#‘) root=NULL;
15 else
16 {
17 root=(TreeNode*)malloc(sizeof(TreeNode));
18 root->a=c;
19 build(root->lchild,s,n);
20 build(root->rchild,s,n);
21 }
22 return true;
23 }
24 void bianli(TreeNode *root)
25 {
26 if(root)
27 {
28 if(root->lchild) bianli(root->lchild);
29 cout<<root->a<<" ";
30 if(root->rchild) bianli(root->rchild);
31 }
32 }
33 int main()
34 {
35 string s;
36 while(cin>>s)
37 {
38 TreeNode *root;
39 int n=0;
40 if(build(root,s,n))
41 {
42 bianli(root);
43 cout<<endl;
44 }
45 }
46 return 0;
47 }