hiho Week 10 register

Ended

Participants:639

Verdict:Accepted
Score:100 / 100
Submitted:2014-09-07 19:30:46

Lang:Java

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
import java.util.Scanner;
public class Main {
    
    public static void main(String[] args) {
        String str1 = "";
        String str2 = "";
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            str1 = in.nextLine();
            str2 = in.nextLine();
            post_order(str1,str2);
        }
    }
    
    static void post_order(String str1String str2) {
        if (str1 == null || str1.equals("")) {
            return;
        }
        if(str1.length() == 1 && str1.equals(str2)) {
            System.out.print(str1);
        } else {
            String root = str1.substring(0,1);
            int index = str2.indexOf(root);
            post_order(str1.substring(1,index+1), str2.substring(0,index));
            post_order(str1.substring(index+1), str2.substring(index+1));
            System.out.print(root);
        }
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX