码迷,mamicode.com
首页 > 其他好文 > 详细

Uva10701 Pre, in and post

时间:2014-10-31 22:09:36      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   ar   sp   div   on   

和Tree Recover基本类似,就改了一点而已

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 string pr,in;
 6 string postorder;
 7 void process(string preord,string inord);
 8 int main()
 9 {
10     int line,order;
11     //freopen("D:\\acm.txt","r",stdin);
12     cin>>line;
13     while(line--){
14         cin>>order;
15         cin>>pr>>in;
16         postorder.clear();
17         process(pr,in);
18         cout<<postorder<<endl;
19     }
20     return 0;
21 }
22 void process(string preord,string inord){
23     int Size = preord.size();
24     if(Size>0){
25         int p = inord.find(preord[0]);
26         process(preord.substr(1,p),inord.substr(0,p));//左树
27         process(preord.substr(p + 1,Size - (p + 1)),inord.substr(p + 1,Size - (p + 1)));//右树
28         postorder.push_back(preord[0]);
29     }
30 }

 

Uva10701 Pre, in and post

标签:style   blog   io   color   os   ar   sp   div   on   

原文地址:http://www.cnblogs.com/ohxiaobai/p/4066024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!