importjava.util.HashMap;importjava.util.LinkedList;importjava.util.Scanner;public classMain{public static voidmain(String[] args) {
LinkedList que=new LinkedList();
HashMap map=new HashMap();
Scanner scan=newScanner(System.in);
String s1=scan.next();
String s2=scan.next();int len=s1.length();
map.put(s1,0);int ans=0;
Node start=newNode();
start.s=s1;start.x=s1.indexOf("*");start.t=0;
que.add(start);while(!que.isEmpty()) {
Node now=que.getFirst();
String nows=now.s;
que.pop();int nowx=now.x;//此时*的位置,准备跳到xx的位置
if(nows.equals(s2)) {
ans=now.t;break;
}for(int i=-3;i<=3;i++){//6种跳法
int xx=nowx+i;//xx是*要跳到的下标的位置
if(i!=0 && xx>=0 && xx
String next;char c[]=nows.toCharArray();//用char数组转换满分过,484ms
c[nowx]=c[xx];
c[xx]=nows.charAt(nowx);
next=newString(c);/*String指定字符交换部分的代码,超时83分。
if(i<0) {//*往左移动
if(nowx==(len-1))//*在最右边
next=nows.substring(0, xx)+"*"+nows.substring(xx+1,nowx)+temp;
else
next=nows.substring(0, xx)+"*"+nows.substring(xx+1,nowx)+temp+nows.substring(nowx+1,len);
}else {//*往右跳移动
if(xx==(len-1))//跳到最右边
next=nows.substring(0,nowx)+temp+nows.substring(nowx+1, xx)+"*";
else
next=nows.substring(0,nowx)+temp+nows.substring(nowx+1, xx)+"*"+nows.substring(xx+1,len);
}*/
if(map.containsKey(next)==false) {//没有跳到此状态过
map.put(next, 1);//标记
Node node=newNode();
node.s=next;
node.x=xx;
node.t=now.t+1;
que.add(node);
}
}
}
}
System.out.println(ans);
}
}classNode{
String s;int x;//* 的位置
int t;//步数
}