且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java求吸血鬼数字算法 。。。

更新时间:2022-08-13 07:47:39

import java.util.*;
public class XiXueGui {
	 public static void main(String []args) throws Exception
	  {    
	   ArrayList<Integer> list=new ArrayList<Integer>(); //提高效率所引用线性表
	   ArrayList<Integer> result=new ArrayList<Integer>(); //防止结果集重复
	     boolean test=true ;  
	     boolean flag=false ;
	    for(int i=11;i<99;i++)
	      for(int j=(1000/i)+1;j<99;j++)  
	         { 
	           list.clear() ;
	           String str1=new Integer(i*j).toString() ;   //相乘后
	           String str2=String.valueOf(i)+String.valueOf(j);    
	           for(int m=0;m<4;m++)
	           {  
	        	   for(int n=0;n<4;n++)
	        	   {  
	        		   test=true ;
	        		   for(int x=0;x<list.size();x++)
	        			   if(n==list.get(x)) test=false ;  //如果表中存在索引
	        		   if(test==false)
	        			   continue ;
	        		   if(str1.charAt(m)==str2.charAt(n))
	        		   {
	        			   list.add(n) ;   
	        			   break ;
	        		   }
	        	   }        	   
	           }	  
	           if(list.size()==4)
	           {  flag=true ;
	        	   for(int count=0;count<result.size();count++)
	        	   {
                       if(result.get(count)==i*j){
                    	   flag= false ;
                       }	        			   
	        	   }
	        	   if(flag!=false)
	        	   {
	        		   System.out.println(i*j+"="+i+"*"+j);
	        		   result.add(i*j) ;
	        	   }      	   
	           }
	         }      
	   }
}