找出四位数的吸血鬼数字:类似1260=21*60

public class Excis4_10 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Search();
	}
	public static void Search(){
//		 int[] factor = new int[4];
		int b = 0;
		int a= 0;
		boolean isMatched = false;
		for( a=11;a<=99;){
			a++;
			for( b =11;b<=99;){
			 b++;
			 if((a*b>1000)&&(a*b<10000)){
				 isMatched = match(a,b);
			 }	
			 if(isMatched){
				System.out.println("这两个数是:"+a+"*"+b+"="+a*b);
			}
			else{
//				System.out.println("这两个数不是吸血鬼数字");
			}
			}
			
		}
		
		
	}
	private static boolean match(int a,int b) {
		// TODO Auto-generated method stub
		int mul = a*b;
		
		int b_unit = b%10;
		int b_ten = b/10;
		int a_unit = a%10;
		int a_ten = a/10;
	
		int mul_thou = mul/1000;
		int mul_hund = (mul-mul_thou*1000)/100;
		int mul_ten = (mul-mul_thou*1000-mul_hund*100)/10;
		int mul_unit = (mul-mul_thou*1000-mul_hund*100-mul_ten*10)%10;
		
		int ab_factor[]={a_unit,a_ten,b_unit,b_ten};
		int mul_factor[]={mul_unit,mul_ten,mul_hund,mul_thou};
		
		boolean[] same = new boolean[4];
//		boolean[] same_multoab = new boolean[4];
		boolean isMatched = false;
		
		for(int i= 0;i<4;i++)
			for(int j= 0;j<4;j++){
				if(ab_factor[i]==mul_factor[j]){
					same[i] = true; 
					mul_factor[j] = -1;
				}
				
			}
//		for(int i= 0;i<4;i++)
//			for(int j= 0;j<4;j++){
//				if(mul_factor[i]==ab_factor[j]){
//					same_multoab[i] = true; 
//					mul_factor[i] = -1;
//				}
//				
//			}
	    if(same[0]&&same[1]&&same[2]&&same[3]){
	    	isMatched = true;
	    	
	    }
	    return isMatched;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值