灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2933回复:0

java求吸血鬼数字算法

楼主#
更多 发布于:2012-09-08 09:45

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) ;
                   }            
               }
             }      
       }
}


摘自 yue7603835的专栏


喜欢0 评分0
游客

返回顶部