#include <vcl.h> #include <string.h> #pragma hdrstop #include "Unit1.h" #include "Unit2.h" #include "Unit3.h" //-------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "XPManifest" #pragma link "acButtons" #pragma resource "*.dfm" #define n 4 TForm1 *Form1; //--------------------------------------------------------------------------- struct TMT { int z; int p[n]; int t[n]; }; TMT P[n], T[n]; int ccc[n],cc[n],c[n],b; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void run() { P[0].z=StrToInt(Form1->StringGrid3->Cells[1][0]); T[0].z=0; ccc[0]=P[0].z; P[1].z=StrToInt(Form1->StringGrid3->Cells[2][0]); T[1].z=0; ccc[1]=P[1].z; P[2].z=StrToInt(Form1->StringGrid3->Cells[3][0]); T[2].z=0; ccc[2]=P[2].z; P[3].z=StrToInt(Form1->StringGrid3->Cells[4][0]); T[3].z=0; ccc[3]=P[3].z; int z; for(z=0; z<n; z++) { for(int i=0; i<n; i++) {P[z].t[i]=0; T[i].p[z]=0; for(int j=0; j<Form1->StringGrid1->ColCount; j++) { if((StrToIntDef(Form1->StringGrid2->Cells[j][i],0))) if(z+1==StrToInt(Form1->StringGrid2->Cells[j][i]))P[z].t[i]++; if((StrToIntDef(Form1->StringGrid1->Cells[j][i],0))) if(z+1==StrToInt(Form1->StringGrid1->Cells[j][i]))T[i].p[z]++; }}}} //--------------------------------------------------------------------------- void search() { AnsiString p,p2,t,t2; int z,j,zz; for(z=0; z<Form1->StringGrid1->RowCount; z++) { p="I(p"+IntToStr(z+1)+")={"; t="O(p"+IntToStr(z+1)+")={"; for(j=0; j<Form1->StringGrid2->RowCount; j++) for(zz=0; zz<Form1->StringGrid2->ColCount; zz++) { if((StrToIntDef(Form1->StringGrid2->Cells[zz][j],0))) if(z+1==StrToInt(Form1->StringGrid2->Cells[zz][j])) { p2="t"+IntToStr(j+1)+","; p+=p2; } if((StrToIntDef(Form1->StringGrid1->Cells[zz][j],0))) if(z+1==StrToInt(Form1->StringGrid1->Cells[zz][j])) { t2="t"+IntToStr(j+1)+","; t+=t2; } } if(p.Pos("t")) p[p.Length()]='}';else p+="}"; Form1->Memo1->Lines->Add(p); if(t.Pos("t")) t[t.Length()]='}';else t+="}"; Form1->Memo2->Lines->Add(t); }} //========================================================= void __fastcall TForm1::FormCreate(TObject *Sender) { for(int i=0; i<Form1->StringGrid1->RowCount; i++) { StringGrid1->Cells[0][i]="I(t"+IntToStr(i+1)+")"; StringGrid2->Cells[0][i]="O(t"+IntToStr(i+1)+")"; } StringGrid3->Cells[0][0]=" м"; StringGrid3->Cells[1][0]="5"; StringGrid3->Cells[2][0]="5"; StringGrid3->Cells[3][0]="5"; StringGrid3->Cells[4][0]="5"; } //========================================================= void spp(int i) { for(int j=0; j<n; j++) if(T[i].p[j]&&T[i].p[j]>P[j].z) {b=0; break;} if(b==1) { for(int j=0; j<n; j++) { T[i].z+=T[i].p[j]; P[j].z-=T[i].p[j]; } for(int k=0; k<n; k++) if(P[k].t[i]!=0&&T[i].z!=0) P[k].z+=P[k].t[i]; } } void kpk() { for(int i=0; i<n; i++) { Form1->TreeView1->Items->AddChild(Form1->TreeView1->Items->Item[0],"0"); Form2->TreeView1->Items->AddChild(Form2->TreeView1->Items->Item[0],"0"); for(int j=0; j<n; j++) { Form1->TreeView1->Items->AddChild(Form1->TreeView1->Items->Item[0]->Item[i],"0"); Form2->TreeView1->Items->AddChild(Form2->TreeView1->Items->Item[0]->Item[i],"0"); for(int e=0; e<n; e++) { Form1->TreeView1->Items->AddChild(Form1->TreeView1->Items->Item[0]->Item[i]->Item[j],"0"); Form2->TreeView1->Items->AddChild(Form2->TreeView1->Items->Item[0]->Item[i]->Item[j],"0"); }}}}//--------------- //======================================= int p1,p2,p3; void run_5() p1=-1; AnsiString f="m("+IntToStr(P[0].z)+","+IntToStr(P[1].z)+","+IntToStr(P[2].z)+","+IntToStr(P[3].z)+")"; Form1->TreeView1->Items->Clear(); Form2->TreeView1->Items->Clear(); Form1->TreeView1->Items->Add(NULL,f); Form2->TreeView1->Items->Add(NULL,f); Form1->TreeView1->Items->Item[0]->Text=f; Form2->TreeView1->Items->Item[0]->Text=f; kpk(); for(int i=n-1; i>-1; i--) {b=1; T[i].z=0; p1++; p2=-1; if(!Form1->CheckBox2->Checked) t1=p1; else t1=i; P[0].z=ccc[0]; P[1].z=ccc[1]; P[2].z=ccc[2]; P[3].z=ccc[3]; spp(p1); AnsiString f="t"+IntToStr(p1+1)+"("+IntToStr(P[0].z)+","+IntToStr(P[1].z)+","+IntToStr(P[2].z)+","+IntToStr(P[3].z)+")"; if(ccc[0]!=P[0].z||ccc[1]!=P[1].z||ccc[2]!=P[2].z||ccc[3]!=P[3].z) { Form1->TreeView1->Items->Item[0]->Item[t1]->Text=f; Form2->TreeView1->Items->Item[0]->Item[t1]->Text=f; cc[0]=P[0].z; cc[1]=P[1].z; cc[2]=P[2].z; cc[3]=P[3].z; } else goto end; for(int j=n-1; j>-1; j--) {b=1; T[j].z=0; p2++; p3=-1; if(!Form1->CheckBox2->Checked) t2=p2; else t2=j; P[0].z=cc[0]; P[1].z=cc[1]; P[2].z=cc[2]; P[3].z=cc[3]; spp(p2); AnsiString f="t"+IntToStr(p2+1)+"("+IntToStr(P[0].z)+","+IntToStr(P[1].z)+","+IntToStr(P[2].z)+","+IntToStr(P[3].z)+")"; if(cc[0]!=P[0].z||cc[1]!=P[1].z||cc[2]!=P[2].z||cc[3]!=P[3].z) { Form1->TreeView1->Items->Item[0]->Item[t1]->Item[t2]->Text=f; Form2->TreeView1->Items->Item[0]->Item[t1]->Item[t2]->Text=f; c[0]=P[0].z; c[1]=P[1].z; c[2]=P[2].z; c[3]=P[3].z; } else goto end1; for(int e=n-1; e>-1; e--) { b=1; T[j].z=0; p3++; if(!Form1->CheckBox2->Checked) t3=p3; else t3=e; P[0].z=c[0]; P[1].z=c[1]; P[2].z=c[2]; P[3].z=c[3]; spp(p3); AnsiString f="t"+IntToStr(p3+1)+"("+IntToStr(P[0].z)+","+IntToStr(P[1].z)+","+IntToStr(P[2].z)+","+IntToStr(P[3].z)+")"; if(c[0]!=P[0].z||c[1]!=P[1].z||c[2]!=P[2].z||c[3]!=P[3].z) { Form1->TreeView1->Items->Item[0]->Item[t1]->Item[t2]->Item[t3]->Text=f; Form2->TreeView1->Items->Item[0]->Item[t1]->Item[t2]->Item[t3]->Text=f; } } end1: }end: } void __fastcall TForm1::acBitBtn2Click(TObject *Sender) { int i=0,j=0; p1=n; b=1; p1=n; Memo1->Clear(); Memo2->Clear(); search(); run(); run_5(); } |