這篇文章主要介紹了C++基于隨機(jī)數(shù)如何實(shí)現(xiàn)福彩雙色球,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
具體如下:
這是前段時(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); }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“C++基于隨機(jī)數(shù)如何實(shí)現(xiàn)福彩雙色球”這篇文章對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián)建站,關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.yijiale78.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
當(dāng)前題目:C++基于隨機(jī)數(shù)如何實(shí)現(xiàn)福彩雙色球-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://www.yijiale78.com/article16/hhdgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、微信小程序、App開發(fā)、ChatGPT、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容