下面贴出源码:
package cn.zimo.algorithm;
import java.util.Scanner;
/**
* 竖式问题
* @author 子墨
* @date 2018年5月2日 下午12:51:54
*/
public class Demo19 {
public static void main(String[] args) {
int abc,de,x,y,z,count=0;
boolean ok=true;
String s,buf;
s=new Scanner(System.in).next();
for(abc=111;abc<=999;abc++) {
for(de=11;de<=99;de++) {
x=abc*(de%10);
y=abc*(de/10);
z=abc*de;
buf=""+abc+de+x+y+z;
ok=true;
for(int i=0;i<buf.length();i++) {
if(!s.contains(buf.charAt(i)+"")) {
ok=false;
break;
}
}
if(ok) {
System.out.printf("<%d>\n",++count);
System.out.printf("%5d\nX%4d\n----\n%5d\n%4d\n----\n%5d\n",abc,de,x,y,z);
}
}
}
System.out.printf("The number of solutions=%4d",count);
}
}