大佬可以帮忙看下第二题我这样做有什么问题吗?
import java.util.ArrayList; import java.util.Scanner; public class Poke { public static void main(String[] args){
Scanner in = new Scanner(System.in); int s=in.nextInt();
String[][]a=new String[s][2]; for(int i=0;i<s;i++){
a[i][0]=in.next();
a[i][0].trim();
a[i][1]=in.next();
}
StringBuilder result=new StringBuilder(); for(int i=0;i<s;i++){
StringBuilder ans=new StringBuilder();
StringBuilder ans2=new StringBuilder();
ArrayList<Integer> mei=new ArrayList<>();
ArrayList<Integer> tmp=new ArrayList<>();
ArrayList<Integer> ming=new ArrayList<>();
String a0=a[i][0];
String a1=a[i][1]; for(int x=0;x<a0.length();x++){
mei.add(a0.charAt(x)-'0');
} for(int x=0;x<a1.length();x++){
ming.add(a1.charAt(x)-'0');
} int count=0; for(int j=0;j<mei.size();j++){ if(!ming.contains(mei.get(j))){
ans.append("d ");
ans2.append("d ");
}else{ if(count==0){
ans.append("l ");
ans2.append("r ");
tmp.add(mei.get(j));
count++;
}else{ if(ming.indexOf(mei.get(j))<ming.indexOf(mei.get(j-1))){
ans.append("l ");
ans2.append("l ");
tmp.add(0,mei.get(j));
}else{
ans.append("r ");
ans2.append("r ");
tmp.add(tmp.size()-1,mei.get(j));
}
}
}
} if(tmp.size()==0){
result.append("{"+"\n");
result.append("}"+"\n"); break;
} for(int x=0;x<tmp.size();x++){ if(tmp.get(x)!=ming.get(x)){
result.append("{"+"\n"+"}"); break;
}
}
result.append("{"+"\n");
result.append(ans);
result.append("\n");
result.append(ans2+"\n");
result.append("}"+"\n");
}
System.out.println(result);
}
}