#include "date1.h"
void m_Sort(int* tab, int s)
{
int i, j, k;
for (i = 1; i < s; i++)
{
j = i;
k = tab[j];
while ((j > 0) && (tab[j - 1] > k))
{
tab[j] = tab[j - 1];
j--;
}
tab[j] = k;
}
}
int kupon1[5] = { 1,3,29,40,42 };
int kupon2[5] = { 2,4,5,39,41 };
int kupon3[5] = {6,7,8,25,26};
bool jest_5(int* tab1, int* tab2, int s)
{
int i,j, sum;
sum = 0;
for (i = 0; i < s; i++)
{
for (j = 0; j < s; j++)
{
if (tab1[i] == tab2[j])
++sum;
}
}
if (sum == 5)
return true;
else
return false;
}
bool jest_4(int* tab1, int* tab2, int s)
{
int i, j, sum;
sum = 0;
for (i = 0; i < s; i++)
{
for (j = 0; j < s; j++)
{
if (tab1[i] == tab2[j])
++sum;
}
}
if (sum == 4)
return true;
else
return false;
}
bool jest_3(int* tab1, int* tab2, int s)
{
int i, j, sum;
sum = 0;
for (i = 0; i < s; i++)
{
for (j = 0; j < s; j++)
{
if (tab1[i] == tab2[j])
++sum;
}
}
if (sum == 3)
return true;
else
return false;
}
bool jest_2(int* tab1, int* tab2, int s)
{
int i, j, sum;
sum = 0;
for (i = 0; i < s; i++)
{
for (j = 0; j < s; j++)
{
if (tab1[i] == tab2[j])
++sum;
}
}
if (sum == 2)
return true;
else
return false;
}
bool jest_1(int* tab1, int* tab2, int s)
{
int i, j, sum;
sum = 0;
for (i = 0; i < s; i++)
{
for (j = 0; j < s; j++)
{
if (tab1[i] == tab2[j])
++sum;
}
}
if (sum == 1)
return true;
else
return false;
}
bool jest_0(int* tab1, int* tab2, int s)
{
int i, j, sum;
sum = 0;
for (i = 0; i < s; i++)
{
for (j = 0; j < s; j++)
{
if (tab1[i] == tab2[j])
++sum;
}
}
if (sum == 0)
return true;
else
return false;
}
Form1.h
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
srand(time(NULL));
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int i, j, k;
int k1[6], k2[6], k3[6];
int temp_Tab[ilosc_Losowan][42];
int** test_Kupon;
test_Kupon = new int* [365];
for (i = 0; i < 365; i++)
test_Kupon[i] = new int[5];
for (i = 0; i < 6; i++)
{
k1[i] = 0; k2[i] = 0; k3[i] = 0;
}
for (i = 0; i < ilosc_Losowan; i++)
for (j = 0; j < 42; j++)
temp_Tab[i][j] = 0;
i = 0;
do
{
j = 0;
do
{
do
{
k = rand() % 42;
} while (temp_Tab[i][k] != 0);
temp_Tab[i][k] = 1;
test_Kupon[i][j] = k + 1;
++j;
} while (j < 5);
++i;
} while (i < ilosc_Losowan);
for (i = 0; i < ilosc_Losowan; i++)
m_Sort(test_Kupon[i], 5);
for (i = 0; i < ilosc_Losowan; i++)
{
if (jest_0(test_Kupon[i], kupon1, 5))
k1[0]++;
if (jest_0(test_Kupon[i], kupon2, 5))
k2[0]++;
if (jest_0(test_Kupon[i], kupon3, 5))
k3[0]++;
if (jest_1(test_Kupon[i], kupon1, 5))
k1[1]++;
if (jest_1(test_Kupon[i], kupon2, 5))
k2[1]++;
if (jest_1(test_Kupon[i], kupon3, 5))
k3[1]++;
if (jest_2(test_Kupon[i], kupon1, 5))
k1[2]++;
if (jest_2(test_Kupon[i], kupon2, 5))
k2[2]++;
if (jest_2(test_Kupon[i], kupon3, 5))
k3[2]++;
if (jest_3(test_Kupon[i], kupon1, 5))
k1[3]++;
if (jest_3(test_Kupon[i], kupon2, 5))
k2[3]++;
if (jest_3(test_Kupon[i], kupon3, 5))
k3[3]++;
if (jest_4(test_Kupon[i], kupon1, 5))
k1[4]++;
if (jest_4(test_Kupon[i], kupon2, 5))
k2[4]++;
if (jest_4(test_Kupon[i], kupon3, 5))
k3[4]++;
if (jest_5(test_Kupon[i], kupon1, 5))
k1[5]++;
if (jest_5(test_Kupon[i], kupon2, 5))
k2[5]++;
if (jest_5(test_Kupon[i], kupon3, 5))
k3[5]++;
}
textBox1->Text = (k1[5]).ToString();
textBox2->Text = (k1[4]).ToString();
textBox3->Text = (k1[3]).ToString();
textBox4->Text = (k1[2]).ToString();
textBox5->Text = (k1[1]).ToString();
textBox6->Text = (k1[0]).ToString();
textBox7->Text = (k2[5]).ToString();
textBox8->Text = (k2[4]).ToString();
textBox9->Text = (k2[3]).ToString();
textBox10->Text =(k2[2]).ToString();
textBox11->Text =(k2[1]).ToString();
textBox12->Text =(k2[0]).ToString();
textBox13->Text = (k3[5]).ToString();
textBox14->Text = (k3[4]).ToString();
textBox15->Text = (k3[3]).ToString();
textBox16->Text = (k3[2]).ToString();
textBox17->Text = (k3[1]).ToString();
textBox18->Text = (k3[0]).ToString();
for (i = 0; i < 365; i++)
delete[] test_Kupon[i];
delete[] test_Kupon;
}
};
}