国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++基于隨機數實現福彩雙色球的方法示例

2020-01-26 14:02:59
字體:
來源:轉載
供稿:網友

本文實例講述了C++基于隨機數實現福彩雙色球的方法。分享給大家供大家參考,具體如下:

這是前段時間寫的福彩雙色球一個小應用

本來可以一個文件搞定,反正也沒多大,就分開了.

頭文件doubleColorBallR2.h

#ifndef _DoubleColorBallR2_h#define _DoubleColorBallR2_h#include <iostream>#include <stdio.h>#include <vector>#include <list>#include "windows.h"#include <algorithm>#ifndef _RED_ZONE_#define _RED_ZONE_ 33#endif#ifndef _BLUE_ZONE_#define _BLUE_ZONE_ 16#endif#ifndef _RED_NUM_#define _RED_NUM_ 6#endif#ifndef _BLUE_NUM_#define _BLUE_NUM_ 1#endifusing namespace std;class DoubleColorBallR2{public:  DoubleColorBallR2(){  }  ~DoubleColorBallR2(){  }  void getRedZone();  void getBlueZone();private:};#endif

實現文件 doubleColorBallR2.cpp

#include "doubleColorBallR2.h"void DoubleColorBallR2::getRedZone(){  vector<int> v_red; //選擇數的范圍 1-_RED_ZONE_  list<int> l_red;  //裝入1-_RED_NUM_個數  for (int i=1; i <= _RED_ZONE_; ++i) {    v_red.push_back(i);  }  srand((unsigned)GetCurrentTime());  int j=_RED_ZONE_;  for (int i=1; i<=_RED_NUM_; ++i) {    int n=1+rand()%(j-1+1);    l_red.push_back(v_red[n]); //裝入    //刪除v_red已裝入的數    vector<int>::iterator iter=find(v_red.begin(), v_red.end(), v_red[n]);    v_red.erase(iter);    --j; //由于v_red已經刪除了一位數,所以隨機數取值范圍要減少一位  }  l_red.sort();  for (list<int>::iterator i=l_red.begin(); i!=l_red.end(); ++i) {    cout<<*i<<" ";  }}void DoubleColorBallR2::getBlueZone(){  vector<int> v_blue; //選擇數的范圍 1-_BLUE_ZONE_  list<int> l_blue;  //裝入1-_BLUE_NUM_個數  for (int i=1; i <= _BLUE_ZONE_; ++i) {    v_blue.push_back(i);  }  srand((unsigned)GetCurrentTime());  int j=_BLUE_ZONE_;  for (int i=1; i<=_BLUE_NUM_; ++i) {    int n=1+rand()%(j-1+1);    l_blue.push_back(v_blue[n]); //裝入    //刪除v_red已裝入的數    vector<int>::iterator iter=find(v_blue.begin(), v_blue.end(), v_blue[n]);    v_blue.erase(iter);    --j; //由于v_red已經刪除了一位數,所以隨機數取值范圍要減少一位  }  l_blue.sort();  for (list<int>::iterator i=l_blue.begin(); i!=l_blue.end(); ++i) {    cout<<*i<<" ";  }}

主程序 doubleColorBall.cpp

#include <iostream>#include <list>#include "windows.h"#include <stdio.h>#include "doubleColorBallR2.h"#define RED_ZONE 33 //紅區#define BLUE_ZONE 16 //藍區#define RED_NUM 6  //紅區位數#define BLUE_NUM 1 //藍區位數using namespace std;int main (int argc, char *argv[]){  DoubleColorBallR2 dcb;  dcb.getRedZone();  dcb.getBlueZone();  getchar();  return(0);}

PS:這里再為大家提供兩款功能類似的在線工具供大家參考:

在線隨機數字/字符串生成工具:
http://tools.VeVB.COm/aideddesign/suijishu

高強度密碼生成器:
http://tools.VeVB.COm/password/CreateStrongPassword

希望本文所述對大家C++程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赣榆县| 襄汾县| 梨树县| 雷波县| 中宁县| 哈密市| 绥中县| 古浪县| 丽水市| 白山市| 南通市| 沅陵县| 河池市| 金沙县| 玉树县| 南木林县| 嘉义市| 石河子市| 青州市| 博野县| 库车县| 北海市| 双鸭山市| 大同县| 贡嘎县| 临安市| 长阳| 南皮县| 长兴县| 马尔康县| 锡林郭勒盟| 赫章县| 德钦县| 台中市| 香港| 田林县| 嘉荫县| 塘沽区| 三门峡市| 克什克腾旗| 萨嘎县|