/*
* 【乘式还原】
* A代表数字0~9中的前5个数字,Z代表后5个数字,请还原下列乘式。
* A Z A
* X A A Z
* ---------
* A A A A
* A A Z Z
* Z A A
* ---------
* Z A Z A A
*/
package test1;
public class demo {
public static void main(String[] args)
{
long i,j,k;
long l,m,n;
long term,mul;
long t1=0,t2=0,t3=0;
int flag;
for(i=0;i<=4;++i)
for(j=5;j<=9;++j)
for(k=0;k<=4;++k)
{
term=100*i+10*j+k;
for(flag=0,n=0;n<=4 && flag==0;)
{
t3=n*term*100;
flag=jud(t3/100,"001");
n++;
}
if(flag==1)
{
for(flag=0,m=0;m<=4 && flag==0;)
{
t2=m*term*10;
flag=jud(t2/10,"1100");
m++;
}
if(flag==1)
{
for(flag=0,l=5;l<=9 && flag==0;)
{
t1=1*term;
flag=jud(t1,"0000");
l++;
}
if(flag==1 && jud(t1+t2+t3,"00101")==1)
{
mul=(n-1)*100+(m-1)*10+(l-1);
print(term,mul,t1,t2,t3);
}
}
}
}
}
static void print(long a,long b,long s1,long s2,long s3)
{
System.out.println(" "+a);
System.out.println("*) "+b);
System.out.println("------------");
System.out.println(" "+s1+"\n"+s2/10+"\n"+s3/100);
System.out.println("------------");
System.out.println(" "+a*b);
}
static int jud(long q,String pflag)
{
int i=0;
while(q!=0 && i<=pflag.length()-1)
if(pflag.charAt(i)-'0'!=(q%10>=5?1:0))
return 0;
else
{
q/=10;
++i;
}
if(q==0 && i==pflag.length())
return 1;
else
return 0;
}
}
* 【乘式还原】
* A代表数字0~9中的前5个数字,Z代表后5个数字,请还原下列乘式。
* A Z A
* X A A Z
* ---------
* A A A A
* A A Z Z
* Z A A
* ---------
* Z A Z A A
*/
package test1;
public class demo {
public static void main(String[] args)
{
long i,j,k;
long l,m,n;
long term,mul;
long t1=0,t2=0,t3=0;
int flag;
for(i=0;i<=4;++i)
for(j=5;j<=9;++j)
for(k=0;k<=4;++k)
{
term=100*i+10*j+k;
for(flag=0,n=0;n<=4 && flag==0;)
{
t3=n*term*100;
flag=jud(t3/100,"001");
n++;
}
if(flag==1)
{
for(flag=0,m=0;m<=4 && flag==0;)
{
t2=m*term*10;
flag=jud(t2/10,"1100");
m++;
}
if(flag==1)
{
for(flag=0,l=5;l<=9 && flag==0;)
{
t1=1*term;
flag=jud(t1,"0000");
l++;
}
if(flag==1 && jud(t1+t2+t3,"00101")==1)
{
mul=(n-1)*100+(m-1)*10+(l-1);
print(term,mul,t1,t2,t3);
}
}
}
}
}
static void print(long a,long b,long s1,long s2,long s3)
{
System.out.println(" "+a);
System.out.println("*) "+b);
System.out.println("------------");
System.out.println(" "+s1+"\n"+s2/10+"\n"+s3/100);
System.out.println("------------");
System.out.println(" "+a*b);
}
static int jud(long q,String pflag)
{
int i=0;
while(q!=0 && i<=pflag.length()-1)
if(pflag.charAt(i)-'0'!=(q%10>=5?1:0))
return 0;
else
{
q/=10;
++i;
}
if(q==0 && i==pflag.length())
return 1;
else
return 0;
}
}