/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作 者:李飞
*完成日期:2016年 6月 12日
*版 本 号:1.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;
}
<img src="https://img-blog.csdn.net/20160612190102221?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />