您的位置:首页 > 其它

洗牌

2016-06-21 13:16 369 查看
/*

 *copyright(c) 2014,烟台大学计算机学院

 *All rights reserved

 *文件名称:test.cpp

 *作者:吴雨凡

 *版本:v6.0

 *

 *问题描述:洗牌

 *输入描述:

 *程序输出:判断相关问题

*/

#include <ctime>

#include <vector>

#include <list>

#include <iostream>

#include <iterator>

#include <cstdlib>

using namespace std;

using namespace std;

typedef vector<int> IntVector;

typedef unsigned int VIndex;

void vectorShuffle(IntVector &unshuffled,IntVector &shuffled)

{

    VIndex p,size=unshuffled.size();

    while(size)

    {

        p=rand()%size--;

        shuffled.push_back(unshuffled[p]);

        unshuffled.erase(unshuffled.begin()+p);

    }

}

int main()

{

    ostream_iterator<int> os(cout," ");

    srand(time(NULL));

    IntVector c,sc;

    for(VIndex i=1; i<=54; i++)

    {

        c.push_back(i);

    }

    cout<<"Before Shuffle"<<endl;

    copy(c.begin(),c.end(),os);

    cout<<endl;

    vectorShuffle(c,sc);

    cout<<"\nAfter Shuffled"<<endl;

    copy(sc.begin(),sc.end(),os);

    cout<<endl<<endl;

    return 0;

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: