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

来源:互联网 发布:mac 桌面上多了个磁盘 编辑:程序博客网 时间:2024/05/29 15:51
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) ;           }                    }         }         }}

原创粉丝点击