C++基于隨機(jī)數(shù)實(shí)現(xiàn)福彩雙色球的方法示例
本文實(shí)例講述了C++基于隨機(jī)數(shù)實(shí)現(xiàn)福彩雙色球的方法。分享給大家供大家參考,具體如下:
這是前段時(shí)間寫的福彩雙色球一個(gè)小應(yīng)用
本來可以一個(gè)文件搞定,反正也沒多大,就分開了.
頭文件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
#endif
using namespace std;
class DoubleColorBallR2
{
public:
DoubleColorBallR2(){
}
~DoubleColorBallR2(){
}
void getRedZone();
void getBlueZone();
private:
};
#endif
實(shí)現(xiàn)文件 doubleColorBallR2.cpp
#include "doubleColorBallR2.h"
void DoubleColorBallR2::getRedZone(){
vector<int> v_red; //選擇數(shù)的范圍 1-_RED_ZONE_
list<int> l_red; //裝入1-_RED_NUM_個(gè)數(shù)
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已裝入的數(shù)
vector<int>::iterator iter=find(v_red.begin(), v_red.end(), v_red[n]);
v_red.erase(iter);
--j; //由于v_red已經(jīng)刪除了一位數(shù),所以隨機(jī)數(shù)取值范圍要減少一位
}
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; //選擇數(shù)的范圍 1-_BLUE_ZONE_
list<int> l_blue; //裝入1-_BLUE_NUM_個(gè)數(shù)
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已裝入的數(shù)
vector<int>::iterator iter=find(v_blue.begin(), v_blue.end(), v_blue[n]);
v_blue.erase(iter);
--j; //由于v_red已經(jīng)刪除了一位數(shù),所以隨機(jī)數(shù)取值范圍要減少一位
}
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 //紅區(qū)
#define BLUE_ZONE 16 //藍(lán)區(qū)
#define RED_NUM 6 //紅區(qū)位數(shù)
#define BLUE_NUM 1 //藍(lán)區(qū)位數(shù)
using namespace std;
int main (int argc, char *argv[])
{
DoubleColorBallR2 dcb;
dcb.getRedZone();
dcb.getBlueZone();
getchar();
return(0);
}
PS:這里再為大家提供兩款功能類似的在線工具供大家參考:
在線隨機(jī)數(shù)字/字符串生成工具:
http://tools.jb51.net/aideddesign/suijishu
高強(qiáng)度密碼生成器:
http://tools.jb51.net/password/CreateStrongPassword
希望本文所述對大家C++程序設(shè)計(jì)有所幫助。
上一篇:C++ 數(shù)據(jù)結(jié)構(gòu)之水洼的數(shù)量算法
欄 目:C語言
下一篇:C++ 數(shù)據(jù)結(jié)構(gòu)線性表-數(shù)組實(shí)現(xiàn)
本文標(biāo)題:C++基于隨機(jī)數(shù)實(shí)現(xiàn)福彩雙色球的方法示例
本文地址:http://www.jygsgssxh.com/a1/Cyuyan/1416.html
您可能感興趣的文章
- 04-02c語言沒有round函數(shù) round c語言
- 01-10深入理解C++中常見的關(guān)鍵字含義
- 01-10使用C++實(shí)現(xiàn)全排列算法的方法詳解
- 01-10c++中inline的用法分析
- 01-10用C++實(shí)現(xiàn)DBSCAN聚類算法
- 01-10全排列算法的非遞歸實(shí)現(xiàn)與遞歸實(shí)現(xiàn)的方法(C++)
- 01-10C++大數(shù)模板(推薦)
- 01-10淺談C/C++中的static與extern關(guān)鍵字的使用詳解
- 01-10深入C/C++浮點(diǎn)數(shù)在內(nèi)存中的存儲(chǔ)方式詳解
- 01-10基于atoi()與itoa()函數(shù)的內(nèi)部實(shí)現(xiàn)方法詳解


閱讀排行
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達(dá)
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達(dá)式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機(jī)閱讀
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 04-02jquery與jsp,用jquery
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子


