<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 97,  comments - 93,  trackbacks - 0
    /**
        *@ the titlt  about a Random example about choose 7 from 33
        *@ the auther Nicky (EN) QuQiang(CH)
        *@ the date   2006.9.1
    **/



    /** the rules

    //一等獎(jiǎng):選中6個(gè)正選號(hào)及特別號(hào);

    //二等獎(jiǎng):選中5個(gè)正選號(hào)及特別號(hào);

    //三等獎(jiǎng):選中5個(gè)正選號(hào);

    //四等獎(jiǎng):選中4個(gè)正選號(hào)及特別號(hào);

    //五等獎(jiǎng):選中4個(gè)正選號(hào)或選中3個(gè)正選號(hào)及特別號(hào);

    //六等獎(jiǎng):選中3個(gè)正選號(hào)。

    **/

    import java.util.*;

    public class NotSameRandoml{
         private static String transform;
         private static String match="00";
         private static int special;


      //產(chǎn)生彩票主邏輯函數(shù)
       private static void Nicky(int[] guess){
          Random r = new Random();     //構(gòu)造偽隨機(jī)生成器
          //某些映射實(shí)現(xiàn)可明確保證其順序,如 TreeMap 類(lèi);某些映射實(shí)現(xiàn)則不保證順序,如 HashMap 類(lèi)
          Map map = new TreeMap();   //Map 接口的實(shí)現(xiàn)
          int n = 0;
          int nt = 1;
          String[] temps=new String[7];
          
          while(true){
              n = r.nextInt(33)+1; //產(chǎn)生1~33的隨機(jī)數(shù)
              //if( map.get(new Integer(n))!=null){
              //   nt = ((Integer)map.get(new Integer(n))).intValue();  
              //}
              //避免了產(chǎn)生的隨機(jī)數(shù)字重復(fù)
              if(map.containsValue(n)){
                continue;
              }
              map.put(new Integer(nt),new Integer(n));//將指定的值與此映射中的指定鍵相關(guān)聯(lián)
              if(map.size()==7){
                 break;
              }
              nt++;
          }
          
          Iterator it = map.keySet().iterator(); //返回此映射中包含的鍵的 set 視圖
          for(int i=0;it.hasNext();i++){
           Object o = it.next();
            // 為了更符合現(xiàn)實(shí)中33選7,數(shù)字為01。。。2位
           int temp=((Integer)map.get(o)).intValue();
           if(temp>=1&&temp<10){
               transform="0"+Integer.toString(temp);
               match=match+" "+transform;
               temps[i]=transform;
               if(((Integer)o).intValue()==7){
                       special=temp;
                       System.out.println(""+transform+"為產(chǎn)生的特別中獎(jiǎng)中獎(jiǎng)號(hào)碼");
                   }else  
                     System.out.println(""+transform+"為產(chǎn)生的第"+((Integer)o).intValue()+"個(gè)中獎(jiǎng)號(hào)碼");
            }else{
            temps[i]=Integer.toString(temp);
            match=match+" "+temps[i];
            if(((Integer)o).intValue()==7){
               System.out.println(""+transform+"為產(chǎn)生的特別中獎(jiǎng)中獎(jiǎng)號(hào)碼");
            }else
            System.out.println(""+temp+"為產(chǎn)生的第"+((Integer)o).intValue()+"個(gè)中獎(jiǎng)號(hào)碼");
           }
          }
          String creat=match.substring(3);
          System.out.println("所產(chǎn)生的中獎(jiǎng)號(hào)碼串為:"+creat);
          //System.out.println("對(duì)產(chǎn)生的中獎(jiǎng)號(hào)碼順序排序?yàn)?"+creats);
          Sort(temps);
          check(map,guess);
       }
       
       //實(shí)現(xiàn)排序,也可以調(diào)用方法,但是卻必須要解決Void問(wèn)題
        private static void Sort(String[] temps) {
             for(int i=0;i<temps.length;i++){
              for(int j=i+1;j<temps.length;j++){
             if(Integer.parseInt(temps[i])>Integer.parseInt(temps[j])){
                String k;
                k=temps[i];temps[i]=temps[j];temps[j]=k;
             }
            }
          }
          System.out.println("對(duì)產(chǎn)生的中獎(jiǎng)號(hào)碼順序排序?yàn)?");
          for(int i=0;i<temps.length;i++){
              System.out.print(temps[i]+" ");
          }
          System.out.println("\n");
        }
       
       
      //輸出結(jié)果類(lèi)別  
       private static void check(Map map ,int[] guess){
            int flag=0;
             for(int i=0;i<guess.length-1;i++){
                if(map.containsValue(guess[i])){
                        flag++;
                    }
             }
             if(guess[guess.length-1]==special){
                flag=flag+10;
             }
             switch(flag){
                  case 16: System.out.println("恭喜您中一等獎(jiǎng)");break;
                  case 15: System.out.println("恭喜您中二等獎(jiǎng)");break;
                  case  5: System.out.println("恭喜您中三等獎(jiǎng)");break;
                  case 14: System.out.println("恭喜您中四等獎(jiǎng)");break;
                  case 13: System.out.println("恭喜您中五等獎(jiǎng)");break;
                  case  4: System.out.println("恭喜您中五等獎(jiǎng)");break;
                  case  3: System.out.println("恭喜您中六等獎(jiǎng)");break;
                  default: System.out.println("謝謝參與,祝您下次中獎(jiǎng)");
             }
       }
       
       
       
      //說(shuō)明
     
       private static void usage(){
          System.out.println("Usage:java Randomol program [the number you guess for the lucky nums.]");
          System.out.println("\t And the nums. you must typed 7,else you will be cancel by the game rules");
          System.out.println("\t The first 6 nums is your basic nums.,the last one is your special num.");
          System.exit(0);
       }
       
       
      //主函數(shù)
       public static void main(String []args){
            if(args.length==0||args.length>7){
                  usage();
                }//帶入?yún)?shù)
                int[] guess=new int[7];
                for(int i=0;i<args.length;i++){
                   guess[i]=Integer.parseInt(args[i]);
                }
                //判斷所輸入的號(hào)碼是否相同
            List <Integer> ls= new ArrayList<Integer>();
            for(int i=0;i<guess.length;i++){
               if(ls.contains(guess[i])){
                  System.out.println("您所買(mǎi)的號(hào)碼不可以相同");
                  System.exit(0);
               }else  ls.add(guess[i]);
            }
            Nicky(guess);      
            System.exit(0);
       }
    }
    posted on 2006-10-12 18:45 wqwqwqwqwq 閱讀(456) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Data Structure && Algorithm
    <2006年10月>
    24252627282930
    1234567
    891011121314
    15161718192021
    22232425262728
    2930311234




    常用鏈接

    留言簿(10)

    隨筆分類(lèi)(95)

    隨筆檔案(97)

    文章檔案(10)

    相冊(cè)

    J2ME技術(shù)網(wǎng)站

    java技術(shù)相關(guān)

    mess

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    校園夢(mèng)網(wǎng)網(wǎng)絡(luò)電話,中國(guó)最優(yōu)秀的網(wǎng)絡(luò)電話
    主站蜘蛛池模板: 最好免费观看韩国+日本| 国产偷v国产偷v亚洲高清| 免费一级做a爰片久久毛片潮| 亚洲精品国产福利一二区| 免费无码又爽又刺激网站直播| 亚洲精品国产成人| 免费高清小黄站在线观看| 岛国精品一区免费视频在线观看 | 久久精品无码专区免费东京热| 7777久久亚洲中文字幕| 亚洲av再在线观看| 精品福利一区二区三区免费视频| 国产精品亚洲精品爽爽| 亚洲尹人九九大色香蕉网站| 国产一级特黄高清免费大片| 免费黄网站在线观看| 国产精品亚洲色婷婷99久久精品| 亚洲天天在线日亚洲洲精| 国产免费人视频在线观看免费| 久久久久久影院久久久久免费精品国产小说| 亚洲欧洲另类春色校园网站| 日韩精品亚洲aⅴ在线影院| 久久久久久99av无码免费网站| 中文字幕av无码不卡免费| 亚洲国产精品成人综合色在线| 亚洲av无码av制服另类专区| 亚洲成?v人片天堂网无码| 性xxxxx免费视频播放| a级毛片免费完整视频| 国产亚洲精品美女久久久久| 亚洲国产片在线观看| 亚洲色欲久久久综合网东京热| 永久免费看bbb| 国产在线观看片a免费观看| a毛片全部免费播放| 免费大片av手机看片高清| 国产日本亚洲一区二区三区| 亚洲av女电影网| 伊伊人成亚洲综合人网7777| 四虎永久成人免费| 成年性午夜免费视频网站不卡|