• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 89  文章 - 118  trackbacks - 0
            <2012年11月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678

            留言簿(16)

            隨筆分類(56)

            隨筆檔案(89)

            文章分類

            推薦博客

            搜索

            •  

            最新隨筆

            最新評論

            閱讀排行榜

            轉自:http://www.fredosaurus.com/notes-cpp/misc/random-shuffle.html

            // File        : misc/random/deal.cpp - Randomly shuffle deck of cards.

            // Illustrates : Shuffle algorithm, srand, rand.

            // Improvements: Use classes for Card and Deck.

            // Author      : Fred Swartz 2003-08-24, shuffle correction 2007-01-18

            //               Placed in the public domain.

             

            #include <iostream>

            #include <cstdlib>   // for srand and rand

            #include <ctime>     // for time

            using namespace std;

             

            int main() {

                int card[52];    // array of cards;

                int n;           // number of cards to deal

                srand(time(0));  // initialize seed "randomly"

                

                for (int i=0; i<52; i++) {

                    card[i] = i;  // fill the array in order

                }

               

                while (cin >> n) {   

                    //--- Shuffle elements by randomly exchanging each with one other.

                    for (int i=0; i<(52-1); i++) {

                        int r = i + (rand() % (52-i)); // Random remaining position.

                        int temp = card[i]; card[i] = card[r]; card[r] = temp;

                    }

                   

                    //--- Print first n cards as ints.

                    for (int c=0; c<n; c++) {

                        cout << card[c] << " ";  // Just print number

                    }

                    cout << endl;

                }

              

               return 0;

            }

            posted on 2012-12-26 15:59 胡滿超 閱讀(549) 評論(0)  編輯 收藏 引用 所屬分類: 算法 、轉載
            久久午夜免费视频| 久久精品亚洲日本波多野结衣| 亚洲综合久久夜AV | 欧美日韩中文字幕久久伊人| 色综合久久久久| 久久只有这精品99| 久久大香香蕉国产| 久久99精品久久久久久水蜜桃 | 久久国产一区二区| 久久精品成人免费国产片小草| 久久强奷乱码老熟女网站| 国内精品久久久久影院一蜜桃| 久久久久国产亚洲AV麻豆| 久久国产精品无码HDAV| 无码人妻久久一区二区三区蜜桃| 久久ZYZ资源站无码中文动漫| 久久高清一级毛片| 国产亚洲婷婷香蕉久久精品| 国产欧美久久久精品影院| 精品视频久久久久| 久久伊人精品青青草原高清| 久久综合给合久久狠狠狠97色| 久久国产免费直播| 国产午夜精品久久久久九九| 久久99国产综合精品| 亚洲国产视频久久| 亚洲国产精品无码久久九九| 久久精品国产亚洲AV不卡| 99久久精品免费看国产免费| 久久这里只精品国产99热| 久久精品国产亚洲av麻豆色欲| 国产A级毛片久久久精品毛片| 伊人精品久久久久7777| 久久久久无码精品国产app| 欧美综合天天夜夜久久| 免费观看久久精彩视频| 国产成人99久久亚洲综合精品| 亚洲午夜久久影院| 久久影院午夜理论片无码| 亚洲伊人久久综合影院| 奇米影视7777久久精品人人爽|