第十五周项目2——洗牌
2016-06-15 18:44
323 查看
问题及代码:
运行结果:
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名称:main.cpp * 作 者:赵志君 * 完成日期:2016年6月15日 * 版 本 号:v1.0 * * 问题描述:在扑克牌游戏中,每次游戏开始都要求把54张牌重新排列一下,称为洗牌。试编写程序将一副扑克牌(用54个整数1~54表示)随机洗好后,顺序输出54张牌的情况。 */ #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<<"洗牌前:"<<endl; copy(poker.begin(),poker.end(),os); cout<<endl; SwapShuffle(poker,100); cout<<"\n洗牌后:"<<endl; copy(poker.begin(),poker.end(),os); cout<<endl<<endl; return 0; }
运行结果:
相关文章推荐
- 【转载】:__I、 __O 、__IO是什么意思?怎么用?
- php实现协程,真正的异步
- [置顶] Java面试题全集(下)
- MySQL数据同步(一主多从)
- 面试心得
- php实现协程,真正的异步
- [c语言] 模拟实现c语言库函数atoi
- mongodb远程连接以及备份、还原、导出、导入
- [置顶] Java面试题全集(中)
- 继承与派生——两个程序的比较
- WebElement.getText()为空解决方法
- window apache+openssl双向认证配置
- JAVA学习之重定向
- 功能介绍与使用说明
- mount:No medium found
- ART虚拟机参数说明
- 耻辱的时间戳(笑哭)
- linux网络编程--UDP协议
- 大数模板
- shell 语句