/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作 者:李飞
*完成日期:2016年 6月 12日
*版 本 号:1.0
*
*问题描述:洗牌游戏解法二
*输入描述:
*程序输出:
*/
#include <ctime>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
using namespace std;
typedef vector<int> IntVector;
void SwapShuffle(IntVector &datas, int time)
{
unsigned size=datas.size(),p1,p2;
while(time--)
{
p1=rand()%size;
p2=rand()%size;
swap(datas[p1],datas[p2]);
}
}
int main()
{
ostream_iterator <int> os(cout," ");
srand(time(NULL));
vector <int> poker;
for(int i=1; i<=54; i++)
{
poker.push_back(i);
}
cout<<"Before Shuffle"<<endl;
copy(poker.begin(),poker.end(),os);
cout<<endl;
SwapShuffle(poker,100);
cout<<"\nAfter Shuffled"<<endl;
copy(poker.begin(),poker.end(),os);
cout<<endl<<endl;
return 0;
}
飛飛(六十五)洗牌游戏解法二
最新推荐文章于 2023-07-15 08:27:41 发布