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

  • 相关阅读:
    国外可用的谷歌地图(可根据地址搜索经纬度)
    后台css框架(自用)
    DBHelp类sql分页(自用笔记)
    定制C++高效安全的运行时动态类型转换
    C++11右值引用和std::move语句实例解析
    浏览器内核-Webkit
    获取股票历史数据和当前数据的API
    从浏览器启动应用程序
    一个实时获取股票数据的安卓应用程序
    C++数据类型总结
  • 原文地址:https://www.cnblogs.com/syf/p/920877.html
Copyright © 2011-2022 走看看