洗牌(1)
来源:互联网 发布:近年来赫哲族人口数据 编辑:程序博客网 时间:2024/05/05 09:43
问题及描述;
/* *Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称;test.cpp *作者;邱凯 *完成日期;2016年6月6号 *版本号;v6.0 *问题描述; 洗牌(1) *输入描述; 输入答案 *输出描述; 输出答案*/#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 shuffled"<<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;}
运行结果;
0 0
- 洗牌(1)
- 项目2-洗牌(1)
- 完美洗牌算法(1)
- 第十五周项目二(1)-洗牌(随机交换两个位置的元素来洗牌)
- 洗牌算法(shuffle)
- hdu 1210(洗牌)
- 洗牌问题(模拟)
- 洗牌(2)
- 洗牌(程序阅读)
- 洗牌
- 洗牌
- 洗牌
- 洗牌
- 洗牌
- 洗牌
- 洗牌
- 洗牌
- 洗牌
- h5 缓存
- ios客户端学习-EGOCache
- Service学习的一些小细节
- 多线程
- PC端和移动端刮卡效果
- 洗牌(1)
- Delaunay三角网
- linux下的Mongodb安装和使用python(linux自带)连接mongo
- git 查看远程分支、本地分支、创建分支、把分支推到远程repository、删除本地分支
- PHPDesigner默认编码方式
- C语言 -- 返回局部变量
- Eclipse智能提示及快捷键
- 边做边学Python Flask Web开发(3)-- Flask Hello World!
- Efficient Adapter for Android