关于随机序列的算法

摘要: 前几天做了个斗地主纸牌程序,根据常理要求三位玩家手中的牌为总数54张牌中的三个随机子序列,设定54张牌与0到53这些键值一一对应,那么要解决的就是产生三个0到53之间的不重复随机序列,之前我采用如下方法:1.先产生一个稍大的随机序列,2.从该主序列中顺次取值构成子序列,3.若当前值已在子序列中,则舍弃当前值,返回2直到完成54个键值的获取,代码如下:void makeCards( vector<int> &player1 ){ //define the three vectors vector<int> key(600,0); vector<int> 阅读全文
posted @ 2011-10-14 20:02 kookest 阅读(329) 评论(0) 推荐(0)

c++文件操作

摘要: 从文件读出向文件写入#include <iostream>#include <vector>#include <string>#include <fstream>using namespace std;int main(){ vector<string> svec; string fileName,str; ifstream inFile; ofstream outFile; cin>>fileName; outFile.open(fileName.c_str(),ios::app);// outFile<<& 阅读全文
posted @ 2011-10-09 12:02 kookest 阅读(115) 评论(0) 推荐(0)