zoukankan      html  css  js  c++  java
  • 小小算法

    import java.util.ArrayList;
    import java.util.Random;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    public class RandomTest {

     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      String sample1[] = {"a","b","0","1","d","c","g","h","i","j","6","7","k","m","3","4","n"};
      String sample2[] = {"p","r","q","s","t","u","v","w","z","y","x","2","5","8","9","e","f"};
      FileWriter wr=null;
      PrintWriter wout=null;
      
      Random r1 = new Random();
      ArrayList al = new ArrayList();
      int page = 0 ;
      for(int i = 0 ; i<10000;)
      {
       if(i%500==0)
       {
        if(wout!=null)
        {
         wout.close();
         wout = null;
        }
        try {
         if(wr!=null)
         {
          wr.close();
          wr = null;
         }
        } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }
        page++;
        try {
         wr=new FileWriter("rand_"+page+".txt");
        } catch (Exception e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
        }
       }
       wout=new PrintWriter(wr);
       StringBuffer sb1 = new StringBuffer();
       for(int k=0;k<6;k++)
       {
        sb1.append(sample1[r1.nextInt(17)]);
       }
       if(!al.contains(sb1.toString()))
       {
        al.add(sb1.toString());
        i++;
       }
       else
       {
        continue;
       }
       ArrayList b1 = new ArrayList();
       Random r2 = new Random();
       for(int j = 0 ; j<10000;)
       {
        StringBuffer sb = new StringBuffer();
        for(int p = 0 ;p<6;p++)
        {
         sb.append(sample2[r2.nextInt(17)]);
        }
        if(!b1.contains(sb.toString()))
        {
         b1.add(sb.toString());
         j++;
         //System.out.println(sb1.toString()+sb.toString());
         wout.println(sb1.toString()+sb.toString());
         wout.flush();
        }
       }
       b1.clear();
      }
      al.clear();
     }
    }

  • 相关阅读:
    foxmail邮箱在代理环境下不能使用解决方法。
    Win7下IE8无法打开https类型的网站解决方法笔记
    重新注册IE组件
    Web开发者的六个代码调试平台
    仿Material UI框架的动画特效
    JS几种数组遍历方式以及性能分析对比
    js 函数提升和变量提升
    彻底掌握this,call,apply
    深入理解requestAnimationFrame
    基于iscroll.js实现下拉刷新和上拉加载特效
  • 原文地址:https://www.cnblogs.com/syf/p/920877.html
Copyright © 2011-2022 走看看