myfunc.cpp
来自「彩票双色球预测算法代码」· C++ 代码 · 共 146 行
CPP
146 行
#include <StdAfx.h>
#include "MyFunc.h"
//rand()产生0-RAND_MAX 的一个随机数,
//RAND_MAX定义在stdlib.h,其值为2147483647,或者32767,这里是3267
//rand()/(RAND_MAX)产生0-1的随机数的函数
//srand( 1024*(unsigned)time( NULL ) ); //随机数种子,两次调用这个函数的时间不能太短
double randf()//产生0-1的一个随机数
{
// srand( 1024*(unsigned)time( NULL ) ); //随机数种子,两次调用这个函数的时间不能太短
return (double)(rand()/(int)RAND_MAX);
}
int random(int number) //产生一个0-number的随机数
{
return (int)(number*rand()/(int)RAND_MAX);
}
int GetRandom(int M,int N)//产生一个从M-N的随机数;
{
int result;
result=random(abs(N-M)+1)+M-1;
return(result);
}
int GetALottary(int M,int N,int P,int Q,int num_red,int num_blue,int Lotta[])
{
int i,j;
bool flag=FALSE;
while(flag==FALSE)
{
srand(10240*(unsigned)time( NULL ));
for( i=0;i<num_red;i++)
Lotta[i]=GetRandom(M,N);//red ball
int temp=0;
int rept=0;
//SetTimer(1,1000,NULL);
for( i=0;i<num_red-1;i++)
{
for(j=i+1;j<num_red;j++)
{
if(Lotta[i]==Lotta[j]) rept++;
if(Lotta[i]>Lotta[j])
{
temp=Lotta[i];
Lotta[i]=Lotta[j];
Lotta[j]=temp;
}
}
if ((rept==0)&&(Lotta[0])!=0) flag=TRUE;//第一个号码不为零,没有重复号码
else flag=false;
}
}
for( i=0;i<num_blue;i++)
Lotta[num_red+i]=GetRandom(P,Q);;//blue ball
return(0);
}
int GetNumSame(int A1[],int A2[],int returnA[], int N)
{
int *a1,*a2,*re;
int same;
a1=new int[N];
a2=new int[N];
re=new int[N];
for(int x=0;x<N;x++)
{
a1[x]=A1[x];
}
for( x=0;x<N;x++)
{
a2[x]=A2[x];
}
same=0;
for(int i=0;i<N;i++)
{
re[i]=0;
for(int j=0;j<N;j++)
{
if(a1[i]==a2[j])
{
re[i]++;
}
}
same=same+re[i];
}
for( x=0;x<N;x++)
{
returnA[x]=re[x];
}
//****************teast OK!*********************
//CString a;
//a.Format("重复的元素数:%d,%d,%d,%d,%d,%d,%d,%d,%d",re[0],re[1],re[2],re[3],re[4],re[5],re[6],re[7],re[8]);
//AfxMessageBox(a);
//*********************************************
delete []a1;
delete []a2;
delete []re;
return(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?