hiho Week 10 register

Ended

Participants:639

Verdict:Accepted
Score:100 / 100
Submitted:2014-09-07 14:09:41

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
void printpostorder(const std::string a, const std::string b){
    std::string::const_iterator start,ed;
    if(a.size()==0) return;
    else if(a.size()==1) cout<<a[0];
    else{
        start=b.begin();
        ed=std::find(b.begin(), b.end(), a[0]);
        std::string str1=a.substr(1,ed-start);
        std::string str2=std::string(a.begin()+1+(ed-start), a.end());
        printpostorder(str1, std::string(start, ed));
        printpostorder(str2, std::string(ed+1, b.end()));
        cout<<a[0];
    }
    return;
}
int main(){
    std::string pre, mid;
    std::getline(cin, pre);
    std::getline(cin, mid);
    printpostorder(pre, mid);
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX