Algorithm training requires a time limit of sorting in the first order: 1.0 s memory limit: MB. The problem description shows the middle and back order of a binary tree. Find its first order. (The agreed Tree node is represented by different uppercase letters, and the length is <= 8 ). The input format is two rows. Each row has one string, indicating a string in the middle and back order. The output format is one string, indicating the first order. The sample input is BADC.
BDCA sample output ABCD analysis: the binary tree simply knows the question of "Middle Order" and "back order" for "first order", and recursively solves the problem
Import java. util. extends; public class Main {public static void main (String [] args) {extends = new loads (System. in); while (partial. hasNext () {String str1 = substring. nextLine (); String str2 = bytes. nextLine (); showResult (str1, str2); System. out. println () ;}} private static void showResult (String str1, String str2) {char chlorophyll = str2.charAt (str2.length ()-1); System. out. print (chlorophyll); int index = str1.indexOf (chlorophyll); if (index> 0) {showResult (str1.substring (0, index), str2.substring (0, index ));} if (index <str1.length ()-1) {showResult (str1.substring (index + 1), str2.substring (index, str2.length ()-1 ));}}}