A,B均为3位数,求A(a1a2a3)经过多少次替换可以使得a1+a2+a3=b1+b2+b3,每次最对可替换其中的一位数字。
import java.util.Scanner;
public class Main {
public static int getCount(int[] a) {
int count=0;
int x=a[0]+a[1]+a[2];
int y=a[3]+a[4]+a[5];
if(x>27||y>27) {
return -1;
}
if(x!=y) {
int t=Math.abs(x-y);
if(t<10) {
count=1;
}
else if(10<=t&&t<=18) {
count=2;
}
else {
count=3;
}
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str=sc.nextLine();
int[] num=new int[str.length()];
for(int i=0;i<str.length();i++) {
num[i]=Integer.parseInt(""+str.charAt(i));
}
System.out.println(getCount(num));
}
}