随便写了个彩票选号的小程序

kahn 2003-12-18 07:23:31
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is a program for lottery :P *
* I wish that you will have fun from it ^_^ *
* Author: Slivermedol *
* Ver 0.1 2003/12/8 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <dos.h>


void lucky36()
{
int lucky[7], tag[37], loop, timedelay, output_temp;
srand(time(NULL)); /* 生成随机数的种子 */
for(loop=0; loop<37; loop++) /* 建立一个标志数组,标志哪些数被取过了 */
tag[loop]=0; /* 若相应数的标志位为0,则表示此数可取 */
for(loop=0; loop<7; loop++)
{
lucky[loop]=rand()%36+1; /* 生成7个36选7的随机数 */
while(1)
{
if(tag[lucky[loop]]==0)
{
tag[lucky[loop]]=1;
break;
}
else
lucky[loop]=lucky[loop]*49%31+3; /* 若本次取到的随机数之前已被取走,则再生成一个 */
}
}
for(loop=0; loop<37; loop++) /* 打印得到的结果 */
{
/*for(timedelay=0; timedelay<8; ++timedelay)
delay(1000000000); */
if(tag[loop]==0)
;
else /* 只有标志数组值中为1的,才能被打印 */
{
printf("%5d", loop);
}
}
printf("\n");
}

main()
{
int i, tag=1;
char choice;
system("cls");
printf("Lucky Today!\n");
printf("Press any key to continue");
getch();
while(tag)
{
printf("\n");
printf("Now Loading"); /* 在屏幕上显示一个用于骗人的Now Loading.... */
for(i=0; i<10; ++i)
{
delay(1000000000);
printf(".");
}
printf("\n");
lucky36();
printf("This is your lucky!!!\n");
printf("Do you want to have another try? \"Y\"or\"N\":");
choice=getch();
switch(choice) /* 选择的结果决定tag,若tag=1,则继续下一次的取数 */
{
case 'y':
case 'Y':
printf("%c\n", choice);
break;
case 'n':
case 'N':
printf("%c\n", choice);
printf("\n");
printf("Thank you for using it");
tag=0; /* 若tag=0,则终止取数,退出程序 */
break;
default:
printf("%c\n", choice);
printf("\n");
printf("Wrong Choice!! It will be terminate!!!");
tag=0; /* 若选择的结果不是Y或y或N或n,则终止程序 */
break;
}
}
}
用来选36选7的,大家说还要加些什么功能,怎么加,我是想加入统计的功能,能对历届的彩票结果做分析后给出结果,而不只是单纯的随机数,大家给个头绪,谢谢
...全文
463 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mme 2003-12-21
  • 打赏
  • 举报
回复
呵呵,给你看看我的,我用了统计的方法。37选7,第一次预测10组,结果有两组中了4个(10块钱)
可惜第二期没有加入新的统计数据,10组最多只中3个(没中奖),我就不想弄了。

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

int result[7];

int SN[36]={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,34,35,36
};
/*
int QN[36]={3,1,1,2,1,1,
1,2,2,0,3,3,
1,1,2,1,1,6,
3,1,2,4,3,2,
2,1,6,2,4,3,
3,2,3,4,4,1
};
*/
int QN[36]={4,5,5,6,7,5,
4,5,2,5,7,4,
5,6,8,1,5,9,
2,9,3,4,5,8,
7,5,4,5,5,9,
8,4,9,5,5,3
};

bool CheckNumber()
{
int i,j,oddnum;
for(i=0; i<7; i++)
{
if(result[i]<1 || result[i]>36)
return false;
}
oddnum = 0;
for(i=0; i<7; i++)
{
j = result[i];
if(j- (int(j/2))*2 != 0)
{
oddnum ++;
}
}
if((oddnum == 2) || (oddnum == 3) || (oddnum == 4) || (oddnum == 5))
{
return true;
}
else
{
return false;
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Button1->Enabled = false;
int R,i,j,k;
int QN1[36];

START:
for(j=0; j<36; j++)
{
QN1[j] = QN[j];
}
randomize();
Sleep(1000);
for(k=0; k<7; k++)
{
AAA: R = random(1000);
while(R <= 100) goto AAA;
i = 0;
while(R > 0)
{
if(i >= 36) i = 0; //i is used to circle the 36 number
R = R - QN1[i];
i++;
}
result[k] = SN[i-1];
QN1[i-1] = 0; //change it's power.
}
if(!CheckNumber())
{
goto START;
}
//ÅÅÐò
int iTemp;
for(i=0; i<7-1; i++)
{
for(j=i+1; j<7; j++)
{
if(result[i] > result[j])
{
iTemp = result[i];
result[i] = result[j];
result[j] = iTemp;
}
}
}

AnsiString str = "";
for(i=0; i<7; i++)
{
str = str + result[i] + " ";
}
Memo1->Lines->Add(str);
Button1->Enabled = true;
}
//---------------------------------------------------------------------------
//为了省代码,所以用了goto
ChinaPlayer 2003-12-21
  • 打赏
  • 举报
回复
建议:
[1] 将历届彩票结果存入一个文件,
[2] 使用的时候,读入内存,并对每个数[e.g.1-36]建立一个数据结构,
typedef struct _INTINFOR
{
int num;//该数
unsigned long int counter;//曾经出现次数
chat other;//附加信息
}INTINFOR;


polly_110 2003-12-20
  • 打赏
  • 举报
回复
还有,你可以这样改一下,让别人先输入他选的号码。然后再产生随机数,看看他的运气如何。其实他的运气就在你的手里了。先看他输入的数,然后在随机数里做点手脚。好多游戏厅里的游戏机都是这样子的,先让你赢,再让你输。
hugos 2003-12-20
  • 打赏
  • 举报
回复
有价值嘛?
polly_110 2003-12-20
  • 打赏
  • 举报
回复
你还可以做点手脚啊。使某些数出现的次数高点。这样好玩一点。
Sirnet 2003-12-20
  • 打赏
  • 举报
回复
钦佩!
hcj2002 2003-12-20
  • 打赏
  • 举报
回复
学习……
red98 2003-12-18
  • 打赏
  • 举报
回复
收藏,有时间看看
间谍 2003-12-18
  • 打赏
  • 举报
回复
收藏一下,楼主好强
ZhangYv 2003-12-18
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/TopicView1.asp?id=2578270

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧