private: // User declarations
bool __fastcall is_First(int value);
int __fastcall is_Min(int x, int y);
int __fastcall is_Fib(int value);
int __fastcall is_Luc(int value);
void __fastcall test_Floyd(int **date, int size);
int *date_First;
int *date_Fib;
int *sum_Way;
int *date_Luc;
int **date_Floyd;
void __fastcall init_Dates();
int __fastcall which_System(int value);
public: // User declarations
#include <vcl.h>
#include <stdlib.h>
#include <time.h>
#pragma hdrstop
#include "m_c_test1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define max 20
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
int i,j;
srand(time(NULL));
date_First=new int[max];
sum_Way=new int[max*max];
date_Fib=new int[max];
date_Luc=new int[max];
date_Floyd=new int *[max];
for(i=0;i<max;i++)
date_Floyd[i]=new int[max];
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
int __fastcall TForm1::is_Fib(int value)
{
if(value<3)
return 1;
else
return is_Fib(value-2)+is_Fib(value-1);
}
int __fastcall TForm1::is_Luc(int value)
{
if(value==1)
return 2;
if(value==2)
return 1;
else
return is_Luc(value-1)+is_Luc(value-2);
}
int __fastcall TForm1::is_Min(int x, int y)
{
if(x<=y)
return x;
else
return y;
}
void __fastcall TForm1::test_Floyd(int **date, int size)
{
int i,j,k,sum,value;;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
for(k=0;k<size;k++)
{
sum=date[j][k]+date[i][k];
value=date[j][k];
date[j][k]=is_Min(sum,value);
}
}
}
}
void __fastcall TForm1::init_Dates()
{
int i,j,k;
i=0;
j=2;
do
{
if(is_First(j))
{
date_First[i]=j;
++i;
}
++j;
}while(i<max);
for(i=0;i<max;i++)
{
date_Luc[i]=is_Luc(i+1);
date_Fib[i]=is_Fib(i+1);
}
}
int __fastcall TForm1::which_System(int value)
{
int temp_random,value_date;
temp_random=rand()%3;
switch (temp_random)
{
case 0:
value_date=date_First[value]; break;
case 1:
value_date=date_Fib[value]; break;
case 2:
value_date=date_Luc[value]; break;
}
return value_date;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Dates();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
int i;
delete date_First;
delete date_Fib;
delete date_Luc;
delete sum_Way;
for(i=0;i<max;i++)
delete [] date_Floyd[i];
delete [] *date_Floyd;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i,j,k,temp_random,value_random;
for(i=0;i<max;i++)
for(j=0;j<max;j++)
date_Floyd[i][j]=99999;
for(i=0;i<max;i++)
{
for(j=0;j<max;j++)
{
temp_random=rand()%max;
if(temp_random<max/2)
{
value_random=rand()%max;
date_Floyd[i][j]=which_System(value_random);
}
}
}
k=1;
for(i=0;i<max;i++)
{
for(j=0;j<max;j++)
{
if(date_Floyd[i][j]==99999)
ListBox1->Items->Add(IntToStr(k)+") "+IntToStr(i)+"<--->"+IntToStr(j)+" FALSE");
else
if(i!=j)
ListBox1->Items->Add(IntToStr(k)+") "+IntToStr(i)+"<--->"+IntToStr(j)+" TRUE");
++k;
}
}
k=1;
for(i=0;i<max;i++)
{
for(j=0;j<max;j++)
{
ListBox2->Items->Add(IntToStr(k)+") "+IntToStr(i)+"<--->"+IntToStr(j)+" = "+IntToStr(date_Floyd[i][j]));
++k;
}
}
k=0;
for(i=0;i<max;i++)
{
for(j=0;j<max;j++)
{
if(date_Floyd[i][j]==99999)
sum_Way[k]=0;
else
sum_Way[k]=date_Floyd[i][j];
++k;
}
}
int temp_Sum[max*max];
int temp;
for(i=0;i<max*max;i++)
{
temp=sum_Way[i];
if(temp==0)
{
temp_Sum[i]=0;
temp=0;
}
else
{
temp+=sum_Way[i];
temp_Sum[i]=temp/2;
}
}
k=1;
for(i=0;i<max*max;i++)
{
ListBox3->Items->Add(IntToStr(k)+") "+IntToStr(temp_Sum[i]));
++k;
}
}
Brak komentarzy:
Prześlij komentarz