#include <stdio.h> #include <time.h> #include <vector> using namespace std; #ifndef _countof #define _countof(array) (sizeof(array)/sizeof(*array)) #endif vector <int> Redball; vector <int> Blueball; int nSelectBalls[7]; static int nRedballs[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 }; static int nBlueballs[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; int MSRand() { memset(nSelectBalls, 0, sizeof(nSelectBalls)); Redball.clear(); Blueball.clear(); for (int i = 0; i < _countof(nRedballs); i++) { Redball.push_back(nRedballs[i]); } for (int j = 0; j < _countof(nBlueballs); j++) { Blueball.push_back(nBlueballs[j]); } // 选红球 for (i = 0; i < 6; i++) { // 随机挑选一个位置 int nIndex = rand() % (33 - i); nSelectBalls[i] = Redball.at(nIndex); vector<int>::iterator it = Redball.begin(); for (it = Redball.begin(); it != Redball.end(); ++it) { if (*it == nSelectBalls[i]) { it = Redball.erase(it); break; } } } // 选蓝球 nSelectBalls[6] = nBlueballs[rand() % 16]; return 0; } int main(int argc, char* argv[]) { char accept[256]; srand(time(0)); // 随机种子 while (1) { int nNoteCount = 0; memset(accept, 0, sizeof(accept)); printf("中国福利彩票<双色球>/n"); printf("[1]机选号码/n"); printf("[2]退出/n"); printf("请输入您的选择[1-2]:"); gets(accept); switch (accept[0]) { case '1': { printf("请您输入机选的注数:"); scanf("%d", &nNoteCount); getchar(); for (int i = 0; i < nNoteCount; i++) { MSRand(); for (int j = 0; j < 7; j++) { printf("%02d/t", nSelectBalls[j]); } printf("/n"); } } break; case '2': { exit(0); } break; } }; return 0; } 效果图: