Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

给你个参考的吧

Posted by faen at 2005-05-25 15:08:02
In Reply To:怎么递归? Posted by:heiheigo at 2005-05-25 13:42:48
import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String [] args)
	{
		Scanner cin=new Scanner(System.in);
		while(cin.hasNext())
		{
			f(cin.next(),cin.next());
			System.out.println();
		}	
		
	}
	private static void f(String pre,String in)
	{
		if(pre.length()==0)
			return;
		if(pre.length()==1)
		{
			System.out.print(pre);
			return;
		}
		char c=pre.charAt(0);
		pre=pre.substring(1);
		String leftin=in.substring(0,in.indexOf(c+""));
		String rightin=in.substring(in.indexOf(c+"")+1);
		String leftpre=pre.substring(0,leftin.length());
		String rightpre=pre.substring(leftin.length());
		f(leftpre,leftin);
		f(rightpre,rightin);
		System.out.print(c);
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator