#include <iostream>
#include <time.h>
#include <stdlib.h>
#define lotto_size 42
#define min_size 5
#define max_size 1000
using namespace std;
int main_Size[min_size];
int test_Size[max_size][min_size];
int temp_Size1[lotto_size];
int temp_Size2[max_size][lotto_size];
void sort_Lotto(int *tab, int m_Size)
{
int i,j,k;
for(i=1;i<m_Size;i++)
{
j=i;
k=tab[j];
while((j>0) && (tab[j-1]>k))
{
tab[j]=tab[j-1];
j--;
}
tab[j]=k;
}
}
bool is_Zero(int *tab1, int *tab2, int msize)
{
int i,j,sum;
sum=0;
j=0;
do
{
for(i=0;i<msize;i++)
if(tab1[j]==tab2[i])
++sum;
++j;
}while(j<msize);
if(sum==0)
return true;
else
return false;
}
bool is_One(int *tab1, int *tab2, int msize)
{
int i,j,sum;
sum=0;
j=0;
do
{
for(i=0;i<msize;i++)
if(tab1[j]==tab2[i])
++sum;
++j;
}while(j<msize);
if(sum==1)
return true;
else
return false;
}
bool is_Two(int *tab1, int *tab2, int msize)
{
int i,j,sum;
sum=0;
j=0;
do
{
for(i=0;i<msize;i++)
if(tab1[j]==tab2[i])
++sum;
++j;
}while(j<msize);
if(sum==2)
return true;
else
return false;
}
bool is_Three(int *tab1, int *tab2, int msize)
{
int i,j,sum;
sum=0;
j=0;
do
{
for(i=0;i<msize;i++)
if(tab1[j]==tab2[i])
++sum;
++j;
}while(j<msize);
if(sum==3)
return true;
else
return false;
}
bool is_Four(int *tab1, int *tab2, int msize)
{
int i,j,sum;
sum=0;
j=0;
do
{
for(i=0;i<msize;i++)
if(tab1[j]==tab2[i])
++sum;
++j;
}while(j<msize);
if(sum==4)
return true;
else
return false;
}
bool is_Five(int *tab1, int *tab2, int msize)
{
int i,j,sum;
sum=0;
j=0;
do
{
for(i=0;i<msize;i++)
if(tab1[j]==tab2[i])
++sum;
++j;
}while(j<msize);
if(sum==5)
return true;
else
return false;
}
void init_Tab()
{
int i,j,k,l;
for(i=0;i<lotto_size;i++)
temp_Size1[i]=0;
for(i=0;i<max_size;i++)
for(j=0;j<lotto_size;j++)
temp_Size2[i][j]=0;
i=0;
do
{
do
{
k=1+rand()%lotto_size;
}while(temp_Size1[k-1]!=0);
temp_Size1[k-1]=1;
main_Size[i]=k;
++i;
}while(i<min_size);
l=0;
do
{
i=0;
do
{
do
{
k=1+rand()%lotto_size;
}while(temp_Size2[i][k-1]!=0);
temp_Size2[l][k-1]=1;
test_Size[l][i]=k;
++i;
}while(i<min_size);
++l;
}while(l<max_size);
sort_Lotto(main_Size,min_size);
for(i=0;i<max_size;i++)
sort_Lotto(test_Size[i],min_size);
}
int main()
{
int i,a0,a1,a2,a3,a4,a5;
a0=a1=a2=a3=a4=a5=0;
srand(time(NULL));
init_Tab();
cout<<"The coupon is drawn (5/42) : \n";
for(i=0;i<min_size;i++)
{
cout<<i+1<<") "<<main_Size[i]<<endl;
}
for(i=0;i<max_size;i++)
{
if(is_Zero(main_Size,test_Size[i],min_size))
++a0;
if(is_One(main_Size,test_Size[i],min_size))
++a1;
if(is_Two(main_Size,test_Size[i],min_size))
++a2;
if(is_Three(main_Size,test_Size[i],min_size))
++a3;
if(is_Four(main_Size,test_Size[i],min_size))
++a4;
if(is_Five(main_Size,test_Size[i],min_size))
++a5;
}
cout<<"\nAnalysis after 1000 draws\n";
cout<<"\n-------------------------------------------------\n";
cout<<"0/5 - "<<a0<<endl;
cout<<"1/5 - "<<a1<<endl;
cout<<"2/5 - "<<a2<<endl;
cout<<"3/5 - "<<a3<<endl;
cout<<"4/5 - "<<a4<<endl;
cout<<"5/5 - "<<a5<<endl;
return 0;
}