| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
给你个参考的吧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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator