第15周项目二—洗牌(2)
2016-06-24 16:51
281 查看
/*烟台大学计算机学院 02.03.*文件名称:xiangmu1.cpp 03.04.*作 者:李亚辉 04.05.*完成日期:2016年6月24日 05.06.*版 本 号:vc++6.0 06.07.* 07.08.*问题描述:洗牌。 08.09.*输入描述: 09. *问题输出: 10.10.*/ #include <iostream> #include <vector> #include <iterator> #include <algorithm> #include <ctime> using namespace std; typedef vector<int> Intvector; void Swapshuff(Intvector &data,int time) { unsigned size=data.size(),p1,p2;//无符号可以储存两倍长度,省略了后面的关键词就默认unsigned int while(time--) { p1=rand()%size; p2=rand()%size; swap(data[p1],data[p2]);//swap函数是namespace中的函数 } } 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; Swapshuff(poker,54); cout<<"After Shuffle:"<<endl; copy(poker.begin(),poker.end(),os); cout<<endl; return 0; } /*学习心得:因为少加了一一个括号
<img src="http://img.blog.csdn.net/20160624165042902?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
相关文章推荐
- Nifi flow 备份恢复
- 子程序循环10次,接着主程序循环100次,然后子程序又循环10次,主程序循环100次,这样循环50次
- 遮挡键盘
- 消息分流器
- Android实战技巧:ViewStub的应用
- 14.4.3.5 Configuring InnoDB Buffer Pool Flushing 配置InnoDB Buffer Pool 刷新:
- collectionView偏移到某一组某一行
- redis常用命令
- 字符串的 宽高计算
- linux设置系统环境变量
- JAVA 本地打印 DocFlavor、DocPrintJob job、PrintService
- mysql-模糊查找数据库和查看数据库的创建语句
- jbpm4.4+Spring集成出现错误org.hibernate.HibernateException: jbpm.hibernate.cfg.xml not found
- LeetCode题解-237-Delete Node in a Linked List
- ORACLE常用系统表大全
- 单例模式
- HTML5 UI 控件Mobiscroll的使用(年月日三级联动)
- 局部富文本
- C语言 单引号 双引号问题
- 14.4.3.5 Configuring InnoDB Buffer Pool Flushing 配置InnoDB Buffer Pool 刷新: